====== cacheExecute ======
~~NOTOC~~
Use of [[v5:reference:adodb_fetch_mode|$ADODB_FETCH_MODE]] and [[v5:reference:connection:setfetchmode|setFetchMode()]] is incompatible with use of cached result sets as the results of the cached query are stored using the original fetch mode settings.
== syntax ==
mixed cacheExecute {
mixed $cacheTimeInSeconds,
optional mixed $sql
optional string[] $bindvars
}
===== Description =====
The function executes a statement and returns a handle to a recordset or false if the statement execution fails.
- If the first parameter passed is a positive integer, then the query cache is searched for a matching query cached within that period. If no matching cache file is found, A new statement is executed and cached.
- If the first parameter is the SQL statement, the query cache default is used [[v5:userguide:local_cache#default_ cache_secs|$cacheSecs]]
===== Parameters =====
==== Parameter 1 ====
The first parameter can be either:
- A positive integer e.g. 600
- A string containing a complete SQL statement, such. ''SELECT * FROM ACT''
- A string containing an SQL statement with bind variables, ''SELECT * FROM ACT WHERE empno>:emp'', in which case the second parameter is an array containing the bind variables
- A array of SQL Statements. This is only available to internal functions.
==== Parameter 2 ====
either the SQL statement or if set, an array of bind variables.
==== Parameter 3 ====
if set, an array of bind variables.
==== Result =====
If the execution succeeds, it returns a recordset. This recordset can be used by functions such as [[v5:reference:connection:getupdatesql|getUpdateSQL()]] or [[v5:reference:recordset:fetchrow|fetchRow()]].
if the execution fails, it returns false. You can access errors using [[v5:reference:connection:errormsg|errorMsg()]].
==== Usage ====
/*
* Connection assumed
*/
$result = $db->cacheExecute(6000,"SELECT * FROM ACT");
or:
$result = $db->cacheExecute("SELECT * FROM ACT WHERE empno > :emp",
array('emp'=>1234)
);
{{tag>[cache]}}