Bug #69257 [Opn->Dup]: Error on PDO MySQL non-emulated statements and repeating the same named param

From: Date: Tue, 28 Sep 2021 10:41:09 +0000
Subject: Bug #69257 [Opn->Dup]: Error on PDO MySQL non-emulated statements and repeating the same named param
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-236887@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69257&edit=1 ID: 69257 Updated by: cmb@php.net Reported by: jrbasso at gmail dot com Summary: Error on PDO MySQL non-emulated statements and repeating the same named param -Status: Open +Status: Duplicate Type: Bug Package: PDO MySQL Operating System: Any PHP Version: 5.6.6 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: This is a duplicate of bug #48856. Previous Comments: ------------------------------------------------------------------------ [2018-01-09 22:22:40] sebastiaanlokhorst at gmail dot com So apparently this is indeed expected behavior: see e.g. http://paul-m-jones.com/archives/243 But this means there's a bug in the emulated statement, as it works there. The behavior should be consistent. ------------------------------------------------------------------------ [2018-01-09 19:20:55] sebastiaanlokhorst at gmail dot com This bug is still present in PHP 7.2. The crazy thing is that it is well known and even expected to fail since the addition mysqlnd support in PDO_mysql in 2008. In the pdo_mysql_prepare_native_dup_named_placeholder.phpt test[1], this exact scenario is tested, and it's expected to fail with "Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number in %s on line %d" https://github.com/php/php-src/blob/master/ext/pdo_mysql/tests/pdo_mysql_prepare_native_dup_named_placeholder.phpt ------------------------------------------------------------------------ [2015-03-18 16:00:39] jrbasso at gmail dot com Description: ------------ When using prepared statements with named parameters that repeats in the statement work fine in emulated prepared statements, but doesn't work in non-emulated mode. The test script is a simple way to reproduce it. Test script: --------------- <?php $pdo = new PDO('mysql:unix_socket=/var/run/mysqld/mysqld.sock;dbname=test;charset=utf8', 'test', 'test'); $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $pdo->prepare('SELECT :a = :a'); $stmt->bindValue(':a', 1, PDO::PARAM_INT); $stmt->execute(); var_dump($stmt->fetchAll(PDO::FETCH_COLUMN)); Expected result: ---------------- array(1) { [0]=> string(1) "1" } Actual result: -------------- PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number' in /home/vagrant/shared/test.php:10 Stack trace: #0 /home/vagrant/shared/test.php(10): PDOStatement->execute() #1 {main} thrown in /home/vagrant/shared/test.php on line 10 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69257&edit=1

« previous php.bugs (#236887) next »