PHP PDO Predefined Constants

PHP PDO 参考手册PHP PDO Reference Manual

The following constants are defined by this extension, and are therefore only available when the extension is compiled into PHP, or dynamically loaded at runtime.

Note:PDO uses class constants since PHP 5.1. Previous versions used the global constant form, such as PDO_PARAM_BOOL.

PDO::PARAM_BOOL (integer)Represents a boolean data type.
PDO::PARAM_NULL (integer)Represents the NULL data type in SQL.
PDO::PARAM_INT (integer)Represents an integer type in SQL.
PDO::PARAM_STR (integer)Represents CHAR, VARCHAR, or other string types in SQL.
PDO::PARAM_LOB (integer)Represents a large object data type in SQL.
PDO::PARAM_STMT (integer)Represents a recordset type. Currently not supported by any driver.
PDO::PARAM_INPUT_OUTPUT (integer)Specifies that the parameter is an INOUT parameter for a stored procedure. You must bitwise-OR this value with an explicit PDO::PARAM_* data type.
PDO::FETCH_LAZY (integer)Specifies the fetch mode: returns each row as an object whose variable names correspond to the column names. PDO::FETCH_LAZY creates the object variable names for access. Not valid in PDOStatement::fetchAll().
PDO::FETCH_ASSOC (integer)Specifies the fetch mode: returns each row as an array indexed by column name. If the result set contains multiple columns with the same name, PDO::FETCH_ASSOC returns only a single value per column name.
PDO::FETCH_NAMED (integer)Specifies the fetch mode: returns each row as an array indexed by column name. If the result set contains multiple columns with the same name, PDO::FETCH_ASSOC returns an array containing values for each column name.
PDO::FETCH_NUM (integer)Specifies the fetch mode: returns each row as an array indexed by column number, starting at column 0.
PDO::FETCH_BOTH (integer)Specifies the fetch mode: returns each row as an array indexed by both column number and column name, starting at column 0.
PDO::FETCH_OBJ (integer)Specifies the fetch mode: returns each row as an object with property names corresponding to the column names.
PDO::FETCH_BOUND (integer)Specifies the fetch mode: returns TRUE and assigns the column values from the result set to PHP variables bound via PDOStatement::bindParam() or PDOStatement::bindColumn().
PDO::FETCH_COLUMN (integer)Specifies the fetch mode: returns the requested column from the next row in the result set.
PDO::FETCH_CLASS (integer)Specifies the fetch mode: returns a new instance of the requested class, mapping columns to the corresponding property names in the class.

Note: If the property does not exist in the requested class, the __set() magic method is called.

PDO::FETCH_INTO (integer)Specifies the fetch mode: updates an existing instance of the requested class, mapping columns to the corresponding property names in the class.
PDO::FETCH_FUNC (integer)Allows data to be handled completely in a custom manner at runtime. (Only valid in PDOStatement::fetchAll().)
PDO::FETCH_GROUP (integer)Returns grouped by value. Usually used together with PDO::FETCH_COLUMN or PDO::FETCH_KEY_PAIR.
PDO::FETCH_UNIQUE (integer)Fetches only unique values.
PDO::FETCH_KEY_PAIR (integer)Fetches a two-column result set into an array, where the first column is the key and the second column is the value. Available since PHP 5.2.3.
PDO::FETCH_CLASSTYPE (integer)Determines the class name based on the value of the first column.
PDO::FETCH_SERIALIZE (integer)Similar to PDO::FETCH_INTO, but represents the object as a serialized string. Available since PHP 5.1.0. As of PHP 5.3.0, if this flag is set, the class constructor is never called.
PDO::FETCH_PROPS_LATE (integer)Calls the constructor before setting properties. Available since PHP 5.2.0.
PDO::ATTR_AUTOCOMMIT (integer)If this value is FALSE, PDO attempts to disable autocommit so that the database connection begins a transaction.
PDO::ATTR_PREFETCH (integer)Sets the prefetch size to balance speed and memory usage for your application. Not all database/driver combinations support setting the prefetch size. A larger prefetch size results in improved performance but also uses more memory.
PDO::ATTR_TIMEOUT (integer)Sets the timeout in seconds for connecting to the database.
PDO::ATTR_ERRMODE (integer)For more information about this attribute, see the Errors and Error Handling section.
PDO::ATTR_SERVER_VERSION (integer)This is a read-only attribute; returns the version information of the database service to which PDO is connected.
PDO::ATTR_CLIENT_VERSION (integer)This is a read-only attribute; returns the version information of the client library used by the PDO driver.
PDO::ATTR_SERVER_INFO (integer)This is a read-only attribute. Returns some metadata about the database service to which PDO is connected.
PDO::ATTR_CONNECTION_STATUS (integer)
PDO::ATTR_CASE (integer)Forces column names to a specified case using constants like PDO::CASE_*.
PDO::ATTR_CURSOR_NAME (integer)Gets or sets the name of the cursor to use. Very useful when using scrollable cursors and positioned updates.
PDO::ATTR_CURSOR (integer)Selects the cursor type. PDO currently supports PDO::CURSOR_FWDONLY and PDO::CURSOR_SCROLL. Typically PDO::CURSOR_FWDONLY, unless you really need a scrollable cursor.
PDO::ATTR_DRIVER_NAME (string)Returns the driver name.

Example of using PDO::ATTR_DRIVER_NAME:

<?php
if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') {
  echo "Running on mysql; doing something mysql specific here\n";
}
?>
PDO::ATTR_ORACLE_NULLS (integer)Converts empty strings to NULL in SQL when fetching data.
PDO::ATTR_PERSISTENT (integer)Requests a persistent connection rather than creating a new one. For more information about this attribute, see Connections and Connection Management.
PDO::ATTR_STATEMENT_CLASS (integer)
PDO::ATTR_FETCH_CATALOG_NAMES (integer)Prepends the contained catalog name to each column name in the result set. The catalog name and column name are separated by a dot (.). This attribute is supported at the driver level, so some drivers may not support it.
PDO::ATTR_FETCH_TABLE_NAMES (integer)Prepends the contained table name to each column name in the result set. The table name and column name are separated by a dot (.). This attribute is supported at the driver level, so some drivers may not support it.
PDO::ATTR_STRINGIFY_FETCHES (integer)
PDO::ATTR_MAX_COLUMN_LEN (integer)
PDO::ATTR_DEFAULT_FETCH_MODE (integer)Available since PHP 5.2.0.
PDO::ATTR_EMULATE_PREPARES (integer)Available since PHP 5.1.3.
PDO::ERRMODE_SILENT (integer)If an error occurs, no error or exception is displayed. Developers are expected to explicitly check for errors. This is the default mode. For more information about this attribute, see Errors and Error Handling.
PDO::ERRMODE_WARNING (integer)If an error occurs, a PHP E_WARNING message is displayed. For more information about this attribute, see Errors and Error Handling.
PDO::ERRMODE_EXCEPTION (integer)If an error occurs, a PDOException is thrown. For more information about this attribute, see Errors and Error Handling.
PDO::CASE_NATURAL (integer)Preserves the column names returned by the database driver.
PDO::CASE_LOWER (integer)Forces column names to lowercase.
PDO::CASE_UPPER (integer)Forces column names to uppercase.
PDO::NULL_NATURAL (integer)
PDO::NULL_EMPTY_STRING (integer)
PDO::NULL_TO_STRING (integer)
PDO::FETCH_ORI_NEXT (integer)Fetches the next row in the result set. Only valid for scrollable cursors.
PDO::FETCH_ORI_PRIOR (integer)Fetches the previous row in the result set. Only valid for scrollable cursors.
PDO::FETCH_ORI_FIRST (integer)Fetches the first row in the result set. Only valid for scrollable cursors.
PDO::FETCH_ORI_LAST (integer)Fetches the last row in the result set. Only valid for scrollable cursors.
PDO::FETCH_ORI_ABS (integer)Fetches the requested row from the result set by row number. Only valid for scrollable cursors.
PDO::FETCH_ORI_REL (integer)Fetches the requested row from the result set by relative position to the current cursor position. Only valid for scrollable cursors.
PDO::CURSOR_FWDONLY (integer)Creates a PDOStatement object with a forward-only cursor. This is the default cursor option because it is the fastest and the most commonly used data access mode in PHP.
PDO::CURSOR_SCROLL (integer)Creates a PDOStatement object with a scrollable cursor. Use the PDO::FETCH_ORI_* constants to control which row is fetched from the result set.
PDO::ERR_NONE (string)Corresponds to SQLSTATE '00000', meaning the SQL statement was issued successfully without errors or warnings. This constant is convenient when using PDO::errorCode() or PDOStatement::errorCode() to determine whether an error occurred. You will often use it when checking the error status code returned by the above methods.
PDO::PARAM_EVT_ALLOC (integer)Allocation event
PDO::PARAM_EVT_FREE (integer)Deallocation event
PDO::PARAM_EVT_EXEC_PRE (integer)An event triggered before executing a prepared statement.
PDO::PARAM_EVT_EXEC_POST (integer)An event triggered after executing a prepared statement.
PDO::PARAM_EVT_FETCH_PRE (integer)An event triggered before fetching a result from a result set.
PDO::PARAM_EVT_FETCH_POST (integer)An event triggered after fetching a result from a result set.
PDO::PARAM_EVT_NORMALIZE (integer)Triggered when binding a parameter, allowing the driver to normalize variable names.

PHP PDO 参考手册PHP PDO Reference Manual

Other Extensions