It should be noted that PDO::FETCH_CLASS will call the constructor *after* setting the values (or calling __set).
Folgende Konstanten werden von dieser Erweiterung definiert und stehen nur zur Verfügung, wenn die Erweiterung entweder statisch in PHP kompiliert oder dynamisch zur Laufzeit geladen wurde.
PDO::PARAM_BOOL
(int)
PDO::PARAM_NULL
(int)
PDO::PARAM_INT
(int)
PDO::PARAM_STR
(int)
PDO::PARAM_STR_NATL
(int)
PDO::PARAM_STR_CHAR
(int)
PDO::PARAM_LOB
(int)
PDO::PARAM_STMT
(int)
PDO::PARAM_INPUT_OUTPUT
(int)
PDO::FETCH_DEFAULT
(int)
PDO::FETCH_LAZY
(int)
PDO::FETCH_LAZY
gibt ein
PDORow-Objekt zurück, das die Eigenschaftsnamen
des Objekts erstellt, sobald auf diese zugegriffen wird. Ungültig
innerhalb von PDOStatement::fetchAll().
PDO::FETCH_ASSOC
(int)
PDO::FETCH_ASSOC
nur einen Wert pro Spaltenname
zurück.
PDO::FETCH_NAMED
(int)
PDO::FETCH_NAMED
ein Array von
Werten pro Spaltenname zurück.
PDO::FETCH_NUM
(int)
PDO::FETCH_BOTH
(int)
PDO::FETCH_OBJ
(int)
PDO::FETCH_BOUND
(int)
PDO::FETCH_COLUMN
(int)
PDO::FETCH_CLASS
(int)
Hinweis: Die magische Methode __set() wird aufgerufen, wenn die Eigenschaft in der angeforderten Klasse nicht vorhanden ist
PDO::FETCH_INTO
(int)
PDO::FETCH_FUNC
(int)
PDO::FETCH_GROUP
(int)
PDO::FETCH_COLUMN
oder
PDO::FETCH_KEY_PAIR
.
PDO::FETCH_UNIQUE
(int)
PDO::FETCH_KEY_PAIR
(int)
PDO::FETCH_CLASSTYPE
(int)
PDO::FETCH_SERIALIZE
(int)
PDO::FETCH_INTO
, liefert aber das Objekt
als serialisierte Zeichenkette. Der Konstruktor wird nicht aufgerufen,
wenn dieses Flag gesetzt ist.
Ab PHP 8.1.0 veraltet.
PDO::FETCH_PROPS_LATE
(int)
PDO::ATTR_AUTOCOMMIT
(int)
false
ist, versucht PDO, Autocommit zu deaktivieren,
damit die Verbindung eine Transaktion starten kann.
PDO::ATTR_PREFETCH
(int)
PDO::ATTR_TIMEOUT
(int)
PDO::ATTR_ERRMODE
(int)
PDO::ATTR_SERVER_VERSION
(int)
PDO::ATTR_CLIENT_VERSION
(int)
PDO::ATTR_SERVER_INFO
(int)
PDO::ATTR_CONNECTION_STATUS
(int)
PDO::ATTR_CASE
(int)
PDO::CASE_*
-Konstanten festgelegt wird.
PDO::ATTR_CURSOR_NAME
(int)
PDO::ATTR_CURSOR
(int)
PDO::CURSOR_FWDONLY
oder
PDO::CURSOR_SCROLL
. Bleiben Sie bei
PDO::CURSOR_FWDONLY
, es sei denn, Sie wissen, dass
Sie einen scrollbaren Cursor benötigen.
PDO::ATTR_DRIVER_NAME
(int)
Beispiel #1 Die Verwendung von PDO::ATTR_DRIVER_NAME
<?php
if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') {
echo "Läuft auf MySQL; macht hier etwas MySQL-spezifisches\n";
}
?>
PDO::ATTR_ORACLE_NULLS
(int)
PDO::ATTR_PERSISTENT
(int)
PDO::ATTR_STATEMENT_CLASS
(int)
PDO::ATTR_FETCH_CATALOG_NAMES
(int)
PDO::ATTR_FETCH_TABLE_NAMES
(int)
PDO::ATTR_STRINGIFY_FETCHES
(int)
PDO::ATTR_MAX_COLUMN_LEN
(int)
PDO::ATTR_DEFAULT_FETCH_MODE
(int)
PDO::ATTR_EMULATE_PREPARES
(int)
PDO::ATTR_DEFAULT_STR_PARAM
(int)
PDO::PARAM_STR_NATL
oder
PDO::PARAM_STR_CHAR
.
Verfügbar seit PHP 7.2.0.
PDO::ERRMODE_SILENT
(int)
PDO::ERRMODE_WARNING
(int)
E_WARNING
-Meldung aus, wenn ein Fehler
auftritt. Weitere Informationen zu diesem Attribut finden Sie im
Abschnitt
Fehler und Fehlerbehandlung.
PDO::ERRMODE_EXCEPTION
(int)
PDO::CASE_NATURAL
(int)
PDO::CASE_LOWER
(int)
PDO::CASE_UPPER
(int)
PDO::NULL_NATURAL
(int)
PDO::NULL_EMPTY_STRING
(int)
PDO::NULL_TO_STRING
(int)
PDO::FETCH_ORI_NEXT
(int)
PDO::FETCH_ORI_PRIOR
(int)
PDO::FETCH_ORI_FIRST
(int)
PDO::FETCH_ORI_LAST
(int)
PDO::FETCH_ORI_ABS
(int)
PDO::FETCH_ORI_REL
(int)
PDO::CURSOR_FWDONLY
(int)
PDO::CURSOR_SCROLL
(int)
PDO::FETCH_ORI_*
, um die aus der Ergebnismenge
abgerufenen Zeilen zu steuern.
PDO::ERR_NONE
(string)
PDO::PARAM_EVT_ALLOC
(int)
PDO::PARAM_EVT_FREE
(int)
PDO::PARAM_EVT_EXEC_PRE
(int)
PDO::PARAM_EVT_EXEC_POST
(int)
PDO::PARAM_EVT_FETCH_PRE
(int)
PDO::PARAM_EVT_FETCH_POST
(int)
PDO::PARAM_EVT_NORMALIZE
(int)
PDO::SQLITE_DETERMINISTIC
(int)
It should be noted that PDO::FETCH_CLASS will call the constructor *after* setting the values (or calling __set).
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.
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
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]
*/
?>
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
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.
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.
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);
'''