Public Member Functions | |
__construct (Connection $conn) | |
Create new statement instance. | |
setLimit ($v) | |
Sets the maximum number of rows to return from db. | |
getLimit () | |
Returns the maximum number of rows to return or 0 for all. | |
setOffset ($v) | |
Sets the start row. | |
getOffset () | |
Returns the start row. | |
close () | |
Free resources associated with this statement. | |
execute ($sql, $fetchmode=null) | |
Generic execute() function has to check to see whether SQL is an update or select query. | |
getResultSet () | |
Get result set. | |
getUpdateCount () | |
Get update count. | |
executeQuery ($sql, $fetchmode=null) | |
Executes the SQL query in this PreparedStatement object and returns the resultset generated by the query. | |
executeUpdate ($sql) | |
Executes the SQL INSERT, UPDATE, or DELETE statement in this PreparedStatement object. | |
getMoreResults () | |
Gets next result set (if this behavior is supported by driver). | |
getConnection () | |
Gets the db Connection that created this statement. | |
Protected Member Functions | |
isSelect ($sql) | |
Returns whether the passed SQL is a SELECT statement. | |
Protected Attributes | |
$conn | |
$resultSet | |
$updateCount | |
$warnings = array() | |
$resultClass | |
$stmt | |
$limit = 0 | |
$offset = 0 |
Definition at line 29 of file StatementCommon.php.
StatementCommon::__construct | ( | Connection $ | conn | ) |
Create new statement instance.
Connection | $conn Connection object |
Definition at line 85 of file StatementCommon.php.
00086 { 00087 $this->conn = $conn; 00088 }
StatementCommon::close | ( | ) |
Free resources associated with this statement.
Some drivers will need to implement this method to free database result resources.
Definition at line 141 of file StatementCommon.php.
StatementCommon::execute | ( | $ | sql, | |
$ | fetchmode = null | |||
) |
Generic execute() function has to check to see whether SQL is an update or select query.
If you already know whether it's a SELECT or an update (manipulating) SQL, then use the appropriate method, as this one will incurr overhead to check the SQL.
int | $fetchmode Fetchmode (only applies to queries). |
SQLException |
Definition at line 157 of file StatementCommon.php.
References executeQuery(), executeUpdate(), and isSelect().
00158 { 00159 00160 if (!$this->isSelect($sql)) { 00161 $this->updateCount = $this->executeUpdate($sql); 00162 return false; 00163 } else { 00164 $this->resultSet = $this->executeQuery($sql, $fetchmode); 00165 if ($this->resultSet->getRecordCount() === 0) { 00166 return false; 00167 } 00168 return true; 00169 } 00170 }
StatementCommon::executeQuery | ( | $ | sql, | |
$ | fetchmode = null | |||
) |
Executes the SQL query in this PreparedStatement object and returns the resultset generated by the query.
string | $sql This method may optionally be called with the SQL statement. | |
int | $fetchmode The mode to use when fetching the results (e.g. ResultSet::FETCHMODE_NUM, ResultSet::FETCHMODE_ASSOC). |
SQLException | If there is an error executing the specified query. |
Reimplemented in MSSQLStatement, and ODBCStatement.
Definition at line 236 of file StatementCommon.php.
Referenced by execute().
00237 { 00238 $this->updateCount = null; 00239 if ($this->limit > 0 || $this->offset > 0) { 00240 $this->conn->applyLimit($sql, $this->offset, $this->limit); 00241 } 00242 $this->resultSet = $this->conn->executeQuery($sql, $fetchmode); 00243 return $this->resultSet; 00244 }
StatementCommon::executeUpdate | ( | $ | sql | ) |
Executes the SQL INSERT, UPDATE, or DELETE statement in this PreparedStatement object.
string | $sql This method may optionally be called with the SQL statement. |
SQLException | if a database access error occurs. |
Definition at line 253 of file StatementCommon.php.
Referenced by execute().
00254 { 00255 if ($this->resultSet) $this->resultSet->close(); 00256 $this->resultSet = null; 00257 $this->updateCount = $this->conn->executeUpdate($sql); 00258 return $this->updateCount; 00259 }
StatementCommon::getConnection | ( | ) |
Gets the db Connection that created this statement.
Definition at line 285 of file StatementCommon.php.
StatementCommon::getLimit | ( | ) |
Returns the maximum number of rows to return or 0 for all.
Definition at line 106 of file StatementCommon.php.
StatementCommon::getMoreResults | ( | ) |
Gets next result set (if this behavior is supported by driver).
Some drivers (e.g. MSSQL) support returning multiple result sets -- e.g. from stored procedures.
This function also closes any current restult set.
Default behavior is for this function to return false. Driver-specific implementations of this class can override this method if they actually support multiple result sets.
Reimplemented in MSSQLStatement.
Definition at line 274 of file StatementCommon.php.
00275 { 00276 if ($this->resultSet) $this->resultSet->close(); 00277 $this->resultSet = null; 00278 return false; 00279 }
StatementCommon::getOffset | ( | ) |
Returns the start row.
Offset only applies when Limit is set!
Definition at line 129 of file StatementCommon.php.
StatementCommon::getResultSet | ( | ) |
Get result set.
This assumes that the last thing done was an executeQuery() or an execute() with SELECT-type query.
Definition at line 179 of file StatementCommon.php.
StatementCommon::getUpdateCount | ( | ) |
Get update count.
null
if not applicable. Definition at line 189 of file StatementCommon.php.
StatementCommon::isSelect | ( | $ | sql | ) | [protected] |
Returns whether the passed SQL is a SELECT statement.
Returns true if SQL starts with 'SELECT' but not 'SELECT INTO'. This exists to support the execute() function -- which could either execute an update or a query.
Currently this function does not take into consideration comments, primarily because there are a number of different comment options for different drivers:
-- SQL-defined comment, but not truly comment in Oracle # comment in mysql /* comment in mssql, others * / // comment sometimes? REM also comment ...
If you're wondering why we can't just execute the query and look at the return results to see whether it was an update or a select, the reason is that for update queries we need to do stuff before we execute them -- like start transactions if auto-commit is off.
string | $sql |
Definition at line 219 of file StatementCommon.php.
Referenced by execute().
00220 { 00221 // is first word is SELECT, then return true, unless it's SELECT INTO ... 00222 // this doesn't, however, take comments into account ... 00223 $sql = trim($sql); 00224 return (stripos($sql, 'select') === 0 && stripos($sql, 'select into ') !== 0); 00225 }
StatementCommon::setLimit | ( | $ | v | ) |
Sets the maximum number of rows to return from db.
This will affect the SQL if the RDBMS supports native LIMIT; if not, it will be emulated. Limit only applies to queries (not update sql).
int | $v Maximum number of rows or 0 for all rows. |
Definition at line 97 of file StatementCommon.php.
StatementCommon::setOffset | ( | $ | v | ) |
Sets the start row.
This will affect the SQL if the RDBMS supports native OFFSET; if not, it will be emulated. Offset only applies to queries (not update) and only is evaluated when LIMIT is set!
int | $v |
Definition at line 119 of file StatementCommon.php.
StatementCommon::$conn [protected] |
Definition at line 35 of file StatementCommon.php.
StatementCommon::$limit = 0 [protected] |
Definition at line 71 of file StatementCommon.php.
StatementCommon::$offset = 0 [protected] |
Definition at line 78 of file StatementCommon.php.
StatementCommon::$resultClass [protected] |
Definition at line 59 of file StatementCommon.php.
StatementCommon::$resultSet [protected] |
Definition at line 41 of file StatementCommon.php.
StatementCommon::$stmt [protected] |
Definition at line 65 of file StatementCommon.php.
StatementCommon::$updateCount [protected] |
Definition at line 47 of file StatementCommon.php.
StatementCommon::$warnings = array() [protected] |
Definition at line 53 of file StatementCommon.php.