class PDOStatement implements IteratorAggregate (View source)

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 1.0.0)
Represents a prepared statement and, after the statement is executed, an associated result set.

Properties

string $queryString

Methods

bool
execute(array $params = null)

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.1.0)
Executes a prepared statement

mixed
fetch(int $mode = PDO::FETCH_DEFAULT, int $cursorOrientation = PDO::FETCH_ORI_NEXT, int $cursorOffset = 0)

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.1.0)
Fetches the next row from a result set

bool
bindParam(mixed $param, mixed $var, int $type = PDO::PARAM_STR, int $maxLength = 0, mixed $driverOptions = null)

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.1.0)
Binds a parameter to the specified variable name

bool
bindColumn(mixed $column, mixed $var, int $type = PDO::PARAM_STR, int $maxLength = 0, mixed $driverOptions = null)

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.1.0)
Bind a column to a PHP variable

bool
bindValue(mixed $param, mixed $value, int $type = PDO::PARAM_STR)

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 1.0.0)
Binds a value to a parameter

int
rowCount()

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.1.0)
Returns the number of rows affected by the last SQL statement

mixed
fetchColumn(int $column = 0)

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.9.0)
Returns a single column from the next row of a result set

array
fetchAll(int $mode = PDO::FETCH_DEFAULT, $fetch_argument = null, mixed ...$args)

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.1.0)
Returns an array containing all of the result set rows

object|false
fetchObject(T> $class = "stdClass", array $constructorArgs = [])

No description

string|null
errorCode()

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.1.0)
Fetch the SQLSTATE associated with the last operation on the statement handle

array
errorInfo()

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.1.0)
Fetch extended error information associated with the last operation on the statement handle

bool
setAttribute(int $attribute, mixed $value)

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.2.0)
Set a statement attribute

mixed
getAttribute(int $name)

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.2.0)
Retrieve a statement attribute

int
columnCount()

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.2.0)
Returns the number of columns in the result set

array|false
getColumnMeta(int $column)

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.2.0)
Returns metadata for a column in a result set

bool
setFetchMode(int $mode, mixed ...$args)

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.2.0)
Set the default fetch mode for this statement

bool
nextRowset()

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.2.0)
Advances to the next rowset in a multi-rowset statement handle

bool
closeCursor()

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.9.0)
Closes the cursor, enabling the statement to be executed again.

bool|null
debugDumpParams()

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.9.0)
Dump an SQL prepared command

__wakeup()

No description

__sleep()

No description

getIterator()

No description

connect()

No description

Details

bool execute(array $params = null)

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.1.0)
Executes a prepared statement

Parameters

array $params

[optional]

An array of values with as many elements as there are bound parameters in the SQL statement being executed. All values are treated as PDO::PARAM_STR.

You cannot bind multiple values to a single parameter; for example, you cannot bind two values to a single named parameter in an IN() clause.

You cannot bind more values than specified; if more keys exist in input_parameters than in the SQL specified in the PDO::prepare, then the statement will fail and an error is emitted.

Return Value

bool

TRUE on success or FALSE on failure.

Exceptions

PDOException

mixed fetch(int $mode = PDO::FETCH_DEFAULT, int $cursorOrientation = PDO::FETCH_ORI_NEXT, int $cursorOffset = 0)

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.1.0)
Fetches the next row from a result set

Parameters

int $mode

[optional]

Controls how the next row will be returned to the caller. This value must be one of the PDO::FETCH_* constants, defaulting to value of PDO::ATTR_DEFAULT_FETCH_MODE (which defaults to PDO::FETCH_BOTH).

PDO::FETCH_ASSOC: returns an array indexed by column name as returned in your result set

int $cursorOrientation

[optional]

For a PDOStatement object representing a scrollable cursor, this value determines which row will be returned to the caller. This value must be one of the PDO::FETCHORI* constants, defaulting to PDO::FETCH_ORI_NEXT. To request a scrollable cursor for your PDOStatement object, you must set the PDO::ATTR_CURSOR attribute to PDO::CURSOR_SCROLL when you prepare the SQL statement with PDO::prepare.

int $cursorOffset [optional]

Return Value

mixed

The return value of this function on success depends on the fetch type. In all cases, FALSE is returned on failure.

bool bindParam(mixed $param, mixed $var, int $type = PDO::PARAM_STR, int $maxLength = 0, mixed $driverOptions = null)

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.1.0)
Binds a parameter to the specified variable name

Parameters

mixed $param

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 $var

Name of the PHP variable to bind to the SQL statement parameter.

int $type

[optional]

Explicit data type for the parameter using the PDO::PARAM_* constants. To return an INOUT parameter from a stored procedure, use the bitwise OR operator to set the PDO::PARAM_INPUT_OUTPUT bits for the data_type parameter.

int $maxLength

[optional]

Length of the data type. To indicate that a parameter is an OUT parameter from a stored procedure, you must explicitly set the length.

mixed $driverOptions

[optional]

Return Value

bool

TRUE on success or FALSE on failure.

bool bindColumn(mixed $column, mixed $var, int $type = PDO::PARAM_STR, int $maxLength = 0, mixed $driverOptions = null)

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.1.0)
Bind a column to a PHP variable

Parameters

mixed $column

Number of the column (1-indexed) or name of the column in the result set. If using the column name, be aware that the name should match the case of the column, as returned by the driver.

mixed $var

Name of the PHP variable to which the column will be bound.

int $type

[optional]

Data type of the parameter, specified by the PDO::PARAM_* constants.

int $maxLength

[optional]

A hint for pre-allocation.

mixed $driverOptions

[optional]

Optional parameter(s) for the driver.

Return Value

bool

TRUE on success or FALSE on failure.

bool bindValue(mixed $param, mixed $value, int $type = PDO::PARAM_STR)

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 1.0.0)
Binds a value to a parameter

Parameters

mixed $param

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 $type

[optional]

Explicit data type for the parameter using the PDO::PARAM_* constants.

Return Value

bool

TRUE on success or FALSE on failure.

int rowCount()

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.1.0)
Returns the number of rows affected by the last SQL statement

Return Value

int

the number of rows.

mixed fetchColumn(int $column = 0)

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.9.0)
Returns a single column from the next row of a result set

Parameters

int $column

[optional]

0-indexed number of the column you wish to retrieve from the row. If no value is supplied, PDOStatement::fetchColumn fetches the first column.

Return Value

mixed

Returns a single column from the next row of a result set or FALSE if there are no more rows.

There is no way to return another column from the same row if you use PDOStatement::fetchColumn to retrieve data.

array fetchAll(int $mode = PDO::FETCH_DEFAULT, $fetch_argument = null, mixed ...$args)

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.1.0)
Returns an array containing all of the result set rows

Parameters

int $mode

[optional]

Controls the contents of the returned array as documented in PDOStatement::fetch. Defaults to value of PDO::ATTR_DEFAULT_FETCH_MODE (which defaults to PDO::FETCH_BOTH)

To return an array consisting of all values of a single column from the result set, specify PDO::FETCH_COLUMN. You can specify which column you want with the column-index parameter.

To fetch only the unique values of a single column from the result set, bitwise-OR PDO::FETCH_COLUMN with PDO::FETCH_UNIQUE.

To return an associative array grouped by the values of a specified column, bitwise-OR PDO::FETCH_COLUMN with PDO::FETCH_GROUP.

$fetch_argument
mixed ...$args

Arguments of custom class constructor when the fetch_style parameter is PDO::FETCH_CLASS.

Return Value

array

PDOStatement::fetchAll returns an array containing all of the remaining rows in the result set. The array represents each row as either an array of column values or an object with properties corresponding to each column name. An empty array is returned if there are zero results to fetch.

Exceptions

PDOException

object|false fetchObject(T> $class = "stdClass", array $constructorArgs = [])

No description

Parameters

T> $class

[optional]

Name of the created class.

array $constructorArgs

[optional]

Elements of this array are passed to the constructor.

Return Value

object|false

an instance of the required class with property names that correspond to the column names or FALSE on failure.

string|null errorCode()

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.1.0)
Fetch the SQLSTATE associated with the last operation on the statement handle

Return Value

string|null

Identical to PDO::errorCode, except that PDOStatement::errorCode only retrieves error codes for operations performed with PDOStatement objects.

array errorInfo()

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.1.0)
Fetch extended error information associated with the last operation on the statement handle

Return Value

array

PDOStatement::errorInfo returns an array of error information about the last operation performed by this statement handle. The array consists of the following fields:

Element Information
0 SQLSTATE error code (a five characters alphanumeric identifier defined in the ANSI SQL standard).
1 Driver specific error code.
2 Driver specific error message.

bool setAttribute(int $attribute, mixed $value)

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.2.0)
Set a statement attribute

Parameters

int $attribute
mixed $value

Return Value

bool

TRUE on success or FALSE on failure.

mixed getAttribute(int $name)

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.2.0)
Retrieve a statement attribute

Parameters

int $name

Return Value

mixed

the attribute value.

int columnCount()

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.2.0)
Returns the number of columns in the result set

Return Value

int

the number of columns in the result set represented by the PDOStatement object. If there is no result set, PDOStatement::columnCount returns 0.

array|false getColumnMeta(int $column)

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.2.0)
Returns metadata for a column in a result set

Parameters

int $column

The 0-indexed column in the result set.

Return Value

array|false

an associative array containing the following values representing the metadata for a single column:

Column metadata
Name Value
native_type The PHP native type used to represent the column value.
driver:decl_type The SQL type used to represent the column value in the database. If the column in the result set is the result of a function, this value is not returned by PDOStatement::getColumnMeta.
flags Any flags set for this column.
name The name of this column as returned by the database.
table The name of this column's table as returned by the database.
len The length of this column. Normally -1 for types other than floating point decimals.
precision The numeric precision of this column. Normally 0 for types other than floating point decimals.
pdo_type The type of this column as represented by the PDO::PARAM_* constants.

Returns FALSE if the requested column does not exist in the result set, or if no result set exists.

bool setFetchMode(int $mode, mixed ...$args)

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.2.0)
Set the default fetch mode for this statement

Parameters

int $mode

The fetch mode must be one of the PDO::FETCH_* constants.

mixed ...$args

Constructor arguments.

Return Value

bool

TRUE on success or FALSE on failure.

bool nextRowset()

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.2.0)
Advances to the next rowset in a multi-rowset statement handle

Return Value

bool

TRUE on success or FALSE on failure.

bool closeCursor()

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.9.0)
Closes the cursor, enabling the statement to be executed again.

Return Value

bool

TRUE on success or FALSE on failure.

bool|null debugDumpParams()

(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.9.0)
Dump an SQL prepared command

Return Value

bool|null

No value is returned.

final __wakeup()

No description

final __sleep()

No description

Traversable getIterator()

Since: 8.0

No description

Return Value

Traversable

An instance of an object implementing Iterator or Traversable

connect()

No description