TYPO3
7.6
|
Public Member Functions | |
__construct ($query, $table, array $precompiledQueryParts=array()) | |
bindValues (array $values) | |
bindValue ($parameter, $value, $data_type=self::PARAM_AUTOTYPE) | |
execute (array $input_parameters=array()) | |
fetch ($fetch_style=0) | |
seek ($rowNumber) | |
fetchAll ($fetch_style=0) | |
free () | |
rowCount () | |
errorCode () | |
errorInfo () | |
setFetchMode ($mode) | |
Public Attributes | |
const | PARAM_NULL = 0 |
const | PARAM_INT = 1 |
const | PARAM_STR = 2 |
const | PARAM_BOOL = 3 |
const | PARAM_AUTOTYPE = 4 |
const | FETCH_ASSOC = 2 |
const | FETCH_NUM = 3 |
Protected Member Functions | |
guessValueType ($value) | |
hasNamedPlaceholders ($query) | |
convertNamedPlaceholdersToQuestionMarks (&$query, array &$parameterValues, array &$precompiledQueryParts) | |
tokenizeQueryParameterMarkers ($query, array $parameterValues) | |
generateParameterWrapToken () | |
Protected Attributes | |
$query | |
$precompiledQueryParts | |
$table | |
$parameters | |
$defaultFetchMode = self::FETCH_ASSOC | |
$statement | |
$fields | |
$buffer | |
$parameterWrapToken | |
TYPO3 prepared statement for DatabaseConnection
USE: In all TYPO3 scripts when you need to create a prepared query: $statement = $GLOBALS['TYPO3_DB']->prepare_SELECTquery('*', 'pages', 'uid = :uid'); $statement->execute(array(':uid' => 2)); while (($row = $statement->fetch()) !== FALSE) { ... } $statement->free();
Definition at line 31 of file PreparedStatement.php.
__construct | ( | $query, | |
$table, | |||
array | $precompiledQueryParts = array() |
||
) |
Creates a new PreparedStatement. Either $query or $queryComponents should be used. Typically $query will be used by native MySQL TYPO3_DB on a ready-to-be-executed query. On the other hand, DBAL will have parse the query and will be able to safely know where parameters are used and will use $queryComponents instead.
This constructor may only be used by
string | $query | SQL query to be executed |
string | $table | FROM table, used to call $GLOBALS['TYPO3_DB']->fullQuoteStr(). |
array | $precompiledQueryParts | Components of the query to be executed private |
Definition at line 160 of file PreparedStatement.php.
References $GLOBALS, PreparedStatement\$precompiledQueryParts, PreparedStatement\$query, PreparedStatement\$table, PreparedStatement\generateParameterWrapToken(), and PreparedStatement\hasNamedPlaceholders().
bindValue | ( | $parameter, | |
$value, | |||
$data_type = self::PARAM_AUTOTYPE |
|||
) |
Binds a value to a corresponding named or question mark placeholder in the SQL statement that was use to prepare the statement.
Example 1: $statement = $GLOBALS['TYPO3_DB']->prepare_SELECTquery('*', 'bugs', 'reported_by = ? AND bug_status = ?'); $statement->bindValue(1, 'goofy'); $statement->bindValue(2, 'FIXED');
Example 2: $statement = $GLOBALS['TYPO3_DB']->prepare_SELECTquery('*', 'bugs', 'reported_by = :nickname AND bug_status = :status'); $statement->bindValue(':nickname', 'goofy'); $statement->bindValue(':status', 'FIXED');
mixed | $parameter | Parameter identifier. For a prepared statement using named placeholders, this will be a parameter name of the form :name. For a prepared statement using question mark placeholders, this will be the 1-indexed position of the parameter. |
mixed | $value | The value to bind to the parameter. |
int | $data_type | Explicit data type for the parameter using the ::PARAM_* constants. If not given, the PHP type of the value will be used instead (int, string, boolean). |
Definition at line 231 of file PreparedStatement.php.
References PreparedStatement\guessValueType().
Referenced by PreparedStatement\bindValues().
bindValues | ( | array | $values | ) |
Binds an array of values to corresponding named or question mark placeholders in the SQL statement that was use to prepare the statement.
Example 1: $statement = $GLOBALS['TYPO3_DB']->prepare_SELECTquery('*', 'bugs', 'reported_by = ? AND bug_status = ?'); $statement->bindValues(array('goofy', 'FIXED'));
Example 2: $statement = $GLOBALS['TYPO3_DB']->prepare_SELECTquery('*', 'bugs', 'reported_by = :nickname AND bug_status = :status'); $statement->bindValues(array(':nickname' => 'goofy', ':status' => 'FIXED'));
array | $values | The values to bind to the parameter. The PHP type of each array value will be used to decide which PARAM_* type to use (int, string, boolean, NULL), so make sure your variables are properly casted, if needed. |
Definition at line 198 of file PreparedStatement.php.
References PreparedStatement\bindValue().
|
protected |
Converts named placeholders into question mark placeholders in a query.
string | $query | |
array | $parameterValues | |
array | $precompiledQueryParts |
Definition at line 598 of file PreparedStatement.php.
References PreparedStatement\$query, elseif, PreparedStatement\hasNamedPlaceholders(), and PreparedStatement\tokenizeQueryParameterMarkers().
Referenced by PreparedStatement\execute().
errorCode | ( | ) |
Returns the error number on the last execute() call.
Definition at line 516 of file PreparedStatement.php.
errorInfo | ( | ) |
Returns an array of error information about the last operation performed by this statement handle. The array consists of the following fields:
Definition at line 531 of file PreparedStatement.php.
execute | ( | array | $input_parameters = array() | ) |
Executes the prepared statement. If the prepared statement included parameter markers, you must either:
Definition at line 290 of file PreparedStatement.php.
References PreparedStatement\$fields, $GLOBALS, PreparedStatement\$parameters, PreparedStatement\$precompiledQueryParts, PreparedStatement\$query, PreparedStatement\convertNamedPlaceholdersToQuestionMarks(), and PreparedStatement\guessValueType().
fetch | ( | $fetch_style = 0 | ) |
Fetches a row from a result set associated with a object.
int | $fetch_style | Controls how the next row will be returned to the caller. This value must be one of the ::FETCH_* constants. If omitted, default fetch mode for this prepared query will be used. |
Definition at line 409 of file PreparedStatement.php.
References PreparedStatement\$buffer, and PreparedStatement\$defaultFetchMode.
Referenced by PreparedStatement\fetchAll().
fetchAll | ( | $fetch_style = 0 | ) |
Returns an array containing all of the result set rows.
int | $fetch_style | Controls the contents of the returned array as documented in TYPO3\CMS\Core\Database\PreparedStatement::fetch().@returnarrayArrayofrows.@api |
Definition at line 478 of file PreparedStatement.php.
References PreparedStatement\fetch().
free | ( | ) |
Releases the cursor. Should always be call after having fetched rows from a query execution.
Definition at line 494 of file PreparedStatement.php.
|
protected |
Generate a random token that is used to wrap the query markers
Definition at line 678 of file PreparedStatement.php.
Referenced by PreparedStatement\__construct().
|
protected |
Guesses the type of a given value.
mixed | $value |
Definition at line 564 of file PreparedStatement.php.
References elseif.
Referenced by PreparedStatement\bindValue(), and PreparedStatement\execute().
|
protected |
Returns TRUE if named placeholers are used in a query.
string | $query |
Definition at line 584 of file PreparedStatement.php.
References PreparedStatement\$query.
Referenced by PreparedStatement\__construct(), and PreparedStatement\convertNamedPlaceholdersToQuestionMarks().
rowCount | ( | ) |
Returns the number of rows affected by the last SQL statement.
Definition at line 505 of file PreparedStatement.php.
seek | ( | $rowNumber | ) |
Moves internal result pointer.
int | $rowNumber | Where to place the result pointer (0 = start) |
Definition at line 461 of file PreparedStatement.php.
setFetchMode | ( | $mode | ) |
Sets the default fetch mode for this prepared query.
int | $mode | One of the ::FETCH_* constants |
Definition at line 546 of file PreparedStatement.php.
|
protected |
Replace the markers with unpredictable token markers.
string | $query | |
array | $parameterValues |
\InvalidArgumentException |
Definition at line 653 of file PreparedStatement.php.
References PreparedStatement\$query.
Referenced by PreparedStatement\convertNamedPlaceholdersToQuestionMarks().
|
protected |
Definition at line 136 of file PreparedStatement.php.
Referenced by PreparedStatement\fetch().
|
protected |
Definition at line 119 of file PreparedStatement.php.
Referenced by PreparedStatement\fetch().
|
protected |
Definition at line 131 of file PreparedStatement.php.
Referenced by PreparedStatement\execute().
|
protected |
Definition at line 112 of file PreparedStatement.php.
Referenced by PreparedStatement\execute().
|
protected |
Definition at line 144 of file PreparedStatement.php.
|
protected |
Definition at line 98 of file PreparedStatement.php.
Referenced by PreparedStatement\__construct(), and PreparedStatement\execute().
|
protected |
|
protected |
Definition at line 126 of file PreparedStatement.php.
|
protected |
Definition at line 105 of file PreparedStatement.php.
Referenced by PreparedStatement\__construct().
const FETCH_ASSOC = 2 |
Definition at line 76 of file PreparedStatement.php.
Referenced by ShortcutToolbarItem\shortcutExists().
const FETCH_NUM = 3 |
Definition at line 84 of file PreparedStatement.php.
const PARAM_AUTOTYPE = 4 |
Definition at line 66 of file PreparedStatement.php.
const PARAM_BOOL = 3 |
Definition at line 59 of file PreparedStatement.php.
const PARAM_INT = 1 |
Definition at line 45 of file PreparedStatement.php.
const PARAM_NULL = 0 |
Definition at line 38 of file PreparedStatement.php.
const PARAM_STR = 2 |
Definition at line 52 of file PreparedStatement.php.