php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65149 MySQL + EMULATE_PREPARES = false cause HY093 error with non unique parameters
Submitted: 2013-06-27 17:34 UTC Modified: 2013-06-27 17:35 UTC
From: ipernet at gmail dot com Assigned:
Status: Closed Package: PDO related
PHP Version: 5.4.16 OS: Slackware 13 x64
Private report: No CVE-ID: None
 [2013-06-27 17:34 UTC] ipernet at gmail dot com
Description:
------------
PHP:
5.4.16

PDO Client API version:
mysqlnd 5.0.10 - 20111026

MySQL:
5.5.18-log (same on 5.6.10-log)

When using "PDO::ATTR_EMULATE_PREPARES => false" with a PDO prepared statement, 
the query fails if it refers to the same named parameter more than once.

Work OK with "PDO::ATTR_EMULATE_PREPARES => true"



Test script:
---------------
CREATE TABLE IF NOT EXISTS `test` (
  `id` int(10) unsigned NOT NULL,
  `date` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

------------------------------------------

********************
* Common test code *
********************

$pdo = new PDO('mysql:host=<HOST>;dbname=<DB>', '<USER>', '<PWD>', array(PDO::ATTR_EMULATE_PREPARES => false));


**********
* Test 1 *
**********
	 
$query	=	$pdo->prepare('INSERT INTO test(id, date) VALUES(:id, :date) ON DUPLICATE KEY UPDATE date = :date');
		
$query->bindValue(':id', 5);
$query->bindValue(':date', time());
		
if( ! $query->execute())
	var_dump($query->errorInfo());


**********
* Test 2 *
**********

$query	=	$pdo->prepare('INSERT INTO test(id, date) VALUES(:date, :date)');
		
$query->bindValue(':date', time());
		
if( ! $query->execute())
	var_dump($query->errorInfo());



**********
* Test 3 *
**********

$query	=	$pdo->prepare('INSERT INTO test(id, date) VALUES(:date, :date2)');
		
$query->bindValue(':date', time());
$query->bindValue(':date2', time());

if( ! $query->execute())
	var_dump($query->errorInfo());

Expected result:
----------------
No error and an inserted row in DB for both test 1, 2 and 3.

Actual result:
--------------
Test 1 & 2 don't work and return:

array(3) { [0] => string(5) "HY093" [1] => NULL [2] => NULL } 

Test 3 works as it does not refer to the same named parameter more than once.

- If you change "PDO::ATTR_EMULATE_PREPARES" to "true", all tests work fine.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-06-27 17:35 UTC] ipernet at gmail dot com
-Status: Open +Status: Closed
 [2013-06-27 17:35 UTC] ipernet at gmail dot com
Duplicate with #64875
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Oct 24 02:03:34 2021 UTC