Bug #81576 [Com]: PDO::MYSQL_ATTR_INIT_COMMAND has int typehint, should be string

From: Date: Sat, 06 Nov 2021 07:54:51 +0000
Subject: Bug #81576 [Com]: PDO::MYSQL_ATTR_INIT_COMMAND has int typehint, should be string
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237577@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81576&edit=1

 ID:                 81576
 Comment by:         matthias dot wirtz at hotmail dot de
 Reported by:        matthias dot wirtz at hotmail dot de
 Summary:            PDO::MYSQL_ATTR_INIT_COMMAND has int typehint,
                     should be string
 Status:             Feedback
 Type:               Bug
 Package:            PDO MySQL
 PHP Version:        8.1.0RC5
 Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

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


Previous Comments:
------------------------------------------------------------------------
[2021-11-03 10:51:33] cmb@php.net

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] cmb@php.net

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


Thread (3 messages)

« previous php.bugs (#237577) next »