Edit report at https://bugs.php.net/bug.php?id=81576&edit=1
ID: 81576
Updated by: [email protected]
Reported by: matthias dot wirtz at hotmail dot de
Summary: PDO::MYSQL_ATTR_INIT_COMMAND has int typehint,
should be string
-Status: Feedback
+Status: Verified
-Type: Bug
+Type: Documentation Problem
Package: PDO MySQL
PHP Version: 8.1.0RC5
-Assigned To: cmb
+Assigned To:
Block user comment: N
Private report: N
New Comment:
> i just noticed that the same code is used to init the connection
> for mysql and sqlite - so while this comment is for mysql the
> actual dbh is for sqlite.
Ah, I see! The values of the driver specific constants overlap, so
setting PDO::MYSQL_ATTR_INIT_COMMAND on an SQLite3 PDO connection is
actually setting PDO::PDO_SQLITE_ATTR_EXTENDED_RESULT_CODES, what
expects an int (could actually be bool, though). This should probably
be documented better, and the SQLite driver specific constants are not
documented at all, although there are three of them[1].
[1] <https://github.com/php/php-src/blob/php-8.1.0RC5/ext/pdo_sqlite/php_pdo_sqlite_int.h>
Previous Comments:
------------------------------------------------------------------------
[2021-11-06 07:54:51] matthias dot wirtz at hotmail dot de
thanks looking at it!
from the docs this attr can only be set when constructing the database handle and i:
"Note, this constant can only be used in the driver_options array when constructing a new database handle."
i just noticed that the same code is used to init the connection for mysql and sqlite - so while this comment is for mysql the actual dbh is for sqlite.
this worked in php8.0 but now fails. i guess it's thrown here:
https://github.com/php/php-src/blame/ee2cec186c35b7b392eeee4821b69b11e11560d0/ext/pdo/pdo_dbh.c#L680
------------------------------------------------------------------------
[2021-11-03 10:51:33] [email protected]
The docs are fixed[1], but I cannot reproduce the reported error,
neither with strict_types nor when setting the attribute via
::setAttribute(). And the implementation doesn't look like this
error could be thrown. What am I missing?
[1] <https://github.com/php/doc-en/commit/b2379902aa98b534a21ad904b82c3f568c9efa32>
------------------------------------------------------------------------
[2021-11-03 10:09:46] [email protected]
Oh, right! Thanks for reporting.
------------------------------------------------------------------------
[2021-10-31 06:09:52] matthias dot wirtz at hotmail dot de
Description:
------------
https://www.php.net/manual/de/ref.pdo-mysql.php
PDO::MYSQL_ATTR_INIT_COMMAND (int) has a int typehint giving me this error in PHP 8.1:
Got error 'PHP message: PHP Fatal error: Uncaught TypeError: Attribute value must be of type int for selected attribute, string given
Shouldn't the command be a string?
Test script:
---------------
new PDO(DB_CONN, DB_USER, DB_PASS, [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4']);
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81576&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.