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

From: Date: Tue, 09 Jan 2018 22:22:41 +0000
Subject: Bug #69257 [Com]: 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-213449@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 Comment by: sebastiaanlokhorst at gmail dot com Reported by: jrbasso at gmail dot com Summary: Error on PDO MySQL non-emulated statements and repeating the same named param Status: Open Type: Bug Package: PDO MySQL Operating System: Any PHP Version: 5.6.6 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [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 (#213449) next »