note 124274 added to pdo.constants
| From: | kevin at kevinlocke dot name | Date: | Tue, 08 Oct 2019 16:38:43 +0000 |
| Subject: | note 124274 added to pdo.constants | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-212552@lists.php.net to get a copy of this message | ||
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
----
Server IP: 208.43.231.9
Probable Submitter: 82.199.157.54 (proxied: 2001:470:b:5c3:8981:bbe:831a:c17c)
----
Manual Page -- http://php.net/manual/en/pdo.constants.php
Edit -- https://master.php.net/note/edit/124274
Del: integrated -- https://master.php.net/note/delete/124274/integrated
Del: useless -- https://master.php.net/note/delete/124274/useless
Del: bad code -- https://master.php.net/note/delete/124274/bad+code
Del: spam -- https://master.php.net/note/delete/124274/spam
Del: non-english -- https://master.php.net/note/delete/124274/non-english
Del: in docs -- https://master.php.net/note/delete/124274/in+docs
Del: other reasons-- https://master.php.net/note/delete/124274
Reject -- https://master.php.net/note/reject/124274
Search -- https://master.php.net/manage/user-notes.php