Costanti predefinite

Queste costanti sono definite da questa estensione e sono disponibili solo se l'estensione è stata compilata nel PHP o se è stata caricata dinamicamente a runtime.

PDO::PARAM_BOOL (int)
Represents a boolean data type.
PDO::PARAM_NULL (int)
Represents the SQL NULL data type.
PDO::PARAM_INT (int)
Represents the SQL INTEGER data type.
PDO::PARAM_STR (int)
Represents the SQL CHAR, VARCHAR, or other string data type.
PDO::PARAM_STR_NATL (int)
Flag to denote a string uses the national character set. Available since PHP 7.2.0
PDO::PARAM_STR_CHAR (int)
Flag to denote a string uses the regular character set. Available since PHP 7.2.0
PDO::PARAM_LOB (int)
Represents the SQL large object data type.
PDO::PARAM_STMT (int)
Represents a recordset type. Not currently supported by any drivers.
PDO::PARAM_INPUT_OUTPUT (int)
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_DEFAULT (int)
Specifies that the default fetch mode shall be used. Available as of PHP 8.0.7.
PDO::FETCH_LAZY (int)
Specifies that the fetch method shall return each row as an object with property names that correspond to the column names returned in the result set. PDO::FETCH_LAZY returns a PDORow object which creates the object property names as they are accessed. Not valid inside PDOStatement::fetchAll().
PDO::FETCH_ASSOC (int)
Specifies that the fetch method shall return each row as an array indexed by column name as returned in the corresponding result set. 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 (int)
Specifies that the fetch method shall return each row as an array indexed by column name as returned in the corresponding result set. If the result set contains multiple columns with the same name, PDO::FETCH_NAMED returns an array of values per column name.
PDO::FETCH_NUM (int)
Specifies that the fetch method shall return each row as an array indexed by column number as returned in the corresponding result set, starting at column 0.
PDO::FETCH_BOTH (int)
Specifies that the fetch method shall return each row as an array indexed by both column name and number as returned in the corresponding result set, starting at column 0.
PDO::FETCH_OBJ (int)
Specifies that the fetch method shall return each row as an object with property names that correspond to the column names returned in the result set.
PDO::FETCH_BOUND (int)
Specifies that the fetch method shall return TRUE and assign the values of the columns in the result set to the PHP variables to which they were bound with the PDOStatement::bindParam() or PDOStatement::bindColumn() methods.
PDO::FETCH_COLUMN (int)
Specifies that the fetch method shall return only a single requested column from the next row in the result set.
PDO::FETCH_CLASS (int)
Specifies that the fetch method shall return a new instance of the requested class, mapping the columns to named properties in the class.

Nota: The magic __set() method is called if the property doesn't exist in the requested class

PDO::FETCH_INTO (int)
Specifies that the fetch method shall update an existing instance of the requested class, mapping the columns to named properties in the class.
PDO::FETCH_FUNC (int)
Allows completely customize the way data is treated on the fly (only valid inside PDOStatement::fetchAll()).
PDO::FETCH_GROUP (int)
Group return by values. Usually combined with PDO::FETCH_COLUMN or PDO::FETCH_KEY_PAIR.
PDO::FETCH_UNIQUE (int)
Fetch only the unique values.
PDO::FETCH_KEY_PAIR (int)
Fetch a two-column result into an array where the first column is a key and the second column is the value.
PDO::FETCH_CLASSTYPE (int)
Determine the class name from the value of first column.
PDO::FETCH_SERIALIZE (int)
As PDO::FETCH_INTO but object is provided as a serialized string. The class constructor is never called if this flag is set. Deprecated as of PHP 8.1.0.
PDO::FETCH_PROPS_LATE (int)
Call the constructor before setting properties.
PDO::ATTR_AUTOCOMMIT (int)
If this value is false, PDO attempts to disable autocommit so that the connection begins a transaction.
PDO::ATTR_PREFETCH (int)
Setting the prefetch size allows you to balance speed against memory usage for your application. Not all database/driver combinations support setting of the prefetch size. A larger prefetch size results in increased performance at the cost of higher memory usage.
PDO::ATTR_TIMEOUT (int)
Sets the timeout value in seconds for communications with the database.
PDO::ATTR_ERRMODE (int)
See the Errors and error handling section for more information about this attribute.
PDO::ATTR_SERVER_VERSION (int)
This is a read only attribute; it will return information about the version of the database server to which PDO is connected.
PDO::ATTR_CLIENT_VERSION (int)
This is a read only attribute; it will return information about the version of the client libraries that the PDO driver is using.
PDO::ATTR_SERVER_INFO (int)
This is a read only attribute; it will return some meta information about the database server to which PDO is connected.
PDO::ATTR_CONNECTION_STATUS (int)
PDO::ATTR_CASE (int)
Force column names to a specific case specified by the PDO::CASE_* constants.
PDO::ATTR_CURSOR_NAME (int)
Get or set the name to use for a cursor. Most useful when using scrollable cursors and positioned updates.
PDO::ATTR_CURSOR (int)
Selects the cursor type. PDO currently supports either PDO::CURSOR_FWDONLY and PDO::CURSOR_SCROLL. Stick with PDO::CURSOR_FWDONLY unless you know that you need a scrollable cursor.
PDO::ATTR_DRIVER_NAME (int)
Returns the name of the driver.

Example #1 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 (int)
Convert empty strings to SQL NULL values on data fetches.
PDO::ATTR_PERSISTENT (int)
Request a persistent connection, rather than creating a new connection. See Connections and Connection management for more information on this attribute.
PDO::ATTR_STATEMENT_CLASS (int)
Sets the class name of which statements are returned as.
PDO::ATTR_FETCH_CATALOG_NAMES (int)
Prepend the containing catalog name to each column name returned in the result set. The catalog name and column name are separated by a decimal (.) character. Support of this attribute is at the driver level; it may not be supported by your driver.
PDO::ATTR_FETCH_TABLE_NAMES (int)
Prepend the containing table name to each column name returned in the result set. The table name and column name are separated by a decimal (.) character. Support of this attribute is at the driver level; it may not be supported by your driver.
PDO::ATTR_STRINGIFY_FETCHES (int)
Forces all values fetched to be treated as strings.
PDO::ATTR_MAX_COLUMN_LEN (int)
Sets the maximum column name length.
PDO::ATTR_DEFAULT_FETCH_MODE (int)
PDO::ATTR_EMULATE_PREPARES (int)
PDO::ATTR_DEFAULT_STR_PARAM (int)
Sets the default string parameter type, this can be one of PDO::PARAM_STR_NATL and PDO::PARAM_STR_CHAR. Available since PHP 7.2.0.
PDO::ERRMODE_SILENT (int)
Do not raise an error or exception if an error occurs. The developer is expected to explicitly check for errors. This is the default mode. See Errors and error handling for more information about this attribute.
PDO::ERRMODE_WARNING (int)
Issue a PHP E_WARNING message if an error occurs. See Errors and error handling for more information about this attribute.
PDO::ERRMODE_EXCEPTION (int)
Throw a PDOException if an error occurs. See Errors and error handling for more information about this attribute.
PDO::CASE_NATURAL (int)
Leave column names as returned by the database driver.
PDO::CASE_LOWER (int)
Force column names to lower case.
PDO::CASE_UPPER (int)
Force column names to upper case.
PDO::NULL_NATURAL (int)
PDO::NULL_EMPTY_STRING (int)
PDO::NULL_TO_STRING (int)
PDO::FETCH_ORI_NEXT (int)
Fetch the next row in the result set. Valid only for scrollable cursors.
PDO::FETCH_ORI_PRIOR (int)
Fetch the previous row in the result set. Valid only for scrollable cursors.
PDO::FETCH_ORI_FIRST (int)
Fetch the first row in the result set. Valid only for scrollable cursors.
PDO::FETCH_ORI_LAST (int)
Fetch the last row in the result set. Valid only for scrollable cursors.
PDO::FETCH_ORI_ABS (int)
Fetch the requested row by row number from the result set. Valid only for scrollable cursors.
PDO::FETCH_ORI_REL (int)
Fetch the requested row by relative position from the current position of the cursor in the result set. Valid only for scrollable cursors.
PDO::CURSOR_FWDONLY (int)
Create a PDOStatement object with a forward-only cursor. This is the default cursor choice, as it is the fastest and most common data access pattern in PHP.
PDO::CURSOR_SCROLL (int)
Create a PDOStatement object with a scrollable cursor. Pass the PDO::FETCH_ORI_* constants to control the rows fetched from the result set.
PDO::ERR_NONE (string)
Corresponds to SQLSTATE '00000', meaning that the SQL statement was successfully issued with no errors or warnings. This constant is for your convenience when checking PDO::errorCode() or PDOStatement::errorCode() to determine if an error occurred. You will usually know if this is the case by examining the return code from the method that raised the error condition anyway.
PDO::PARAM_EVT_ALLOC (int)
Allocation event
PDO::PARAM_EVT_FREE (int)
Deallocation event
PDO::PARAM_EVT_EXEC_PRE (int)
Event triggered prior to execution of a prepared statement.
PDO::PARAM_EVT_EXEC_POST (int)
Event triggered subsequent to execution of a prepared statement.
PDO::PARAM_EVT_FETCH_PRE (int)
Event triggered prior to fetching a result from a resultset.
PDO::PARAM_EVT_FETCH_POST (int)
Event triggered subsequent to fetching a result from a resultset.
PDO::PARAM_EVT_NORMALIZE (int)
Event triggered during bound parameter registration allowing the driver to normalize the parameter name.
PDO::SQLITE_DETERMINISTIC (int)
Specifies that a function created with PDO::sqliteCreateFunction() is deterministic, i.e. it always returns the same result given the same inputs within a single SQL statement. (Available as of PHP 7.1.4.)
add a note add a note

User Contributed Notes 8 notes

up
21
sam at xnet dot tk
11 years ago
It should be noted that PDO::FETCH_CLASS will call the constructor *after* setting the values (or calling __set).
up
4
todd at toddwiggins dot com dot au
4 years ago
Reference to all the PDO::MYSQL_* constants is available in MySQL's documentation for the driver here: https://dev.mysql.com/doc/connectors/en/apis-php-pdo-mysql.html

Such as the ones I was looking for PDO::MYSQL_ATTR_SSL_CA and PDO::MYSQL_ATTR_SSL_CAPATH which are not listed on this page.
up
4
kevin at kevinlocke dot name
5 years ago
PDO::PARAM_STR_CHAR and PDO::PARAM_STR_NATL must be combined with PDO::PARAM_STR using bitwise-OR for parameter binding.

These flags control value quoting (e.g. PDO::quote) and, in some situations (see below), parameter binding  (e.g. PDO::bindParam, PDO::bindValue) to prefix string literals with N'' as defined in SQL-92.  As of PHP 7.3, only dblib and mysql support these flags.  For the mysql driver, the flags only affect parameter binding when PDO::ATTR_EMULATE_PREPARES is true (the default).

MySQL and MariaDB interpret string literals prefixed with N as being utf8 (not utf8mb4) regardless of `SET NAMES` or the charset parameter.  This can cause problems if the database/table/column charset is not utf8.  For example, in a database using utf8mb4, the query "SELECT * FROM table WHERE col = :param" and bindValue(":param", "\u{1F600}", PDO::PARAM_STR | PDO::PARAM_STR_NATL) will cause "PDOException: SQLSTATE[HY000]: General error: 1267 Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='".  Using PDO::PARAM_STR without PDO::PARAM_STR_NATL and ensuring the charset DSN parameter is set correctly can avoid this issue.

See:
https://wiki.php.net/rfc/extended-string-types-for-pdo
https://mariadb.com/kb/en/library/string-literals/
https://dev.mysql.com/doc/refman/8.0/en/string-literals.html
up
2
Sbastien
4 years ago
PDO::FETCH_UNIQUE not only fetches the unique values, it also uses the first SQL column as array key result, what is very useful for create quickly an index, eg :

<?php

$sql
= <<<SQL
    SELECT ALL
        c1, -- For result indexing
        c1, c2
    FROM (
        VALUES
            ROW('ID-1', 'Value 1'),
            ROW('ID-2', 'Value 2a'),
            ROW('ID-2', 'Value 2b'),
            ROW('ID-3', 'Value 3')
    ) AS t (c1, c2);
    SQL;
$result = $pdo->query($sql);
print_r(
$result->fetchAll(PDO::FETCH_UNIQUE));

/*
Gives :
ID-1 => [c1 => ID-1,  c2 => Value 1]
ID-2 => [c1 => ID-2b, c2 => Value 2b]
ID-3 => [c1 => ID-3,  c2 => Value 3]
*/

?>
up
5
Oleg Andreyev
8 years ago
Default value for \PDO::ATTR_TIMEOUT is 30 seconds.
Ref.: https://github.com/php/php-src/blob/PHP-7.1.0/ext/pdo_mysql/mysql_driver.c#L600
up
0
happy dot job7348 at fastmail dot com
9 months ago
To bind a float, use PDO::PARAM_STR with bindValue. You can skip the PDO::PARAM_STR because it's the default option. Binding with bindParam will change the type of the bound variable to a string, which can lead to type errors.
up
0
Rexana
1 year ago
Reference for PDO MySQL constants Todd mentioned have moved to here: https://www.php.net/manual/en/ref.pdo-mysql.php

This includes documentation on constants like PDO::MYSQL_ATTR_SSL_CA, PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT, and more.
up
-5
ko dot izawa at gmail dot com
8 years ago
When you use REAL type column on SQLite, your setting of pdo parameter of bindValue() is PDO::PARAM_STR.

'''
$stmt->bindValue(':elapse_time', $e_time, PDO::PARAM_STR);
'''
To Top