Edit report at https://bugs.php.net/bug.php?id=64875&edit=1

 ID:                 64875
 Updated by:         u...@php.net
 Reported by:        zuohaocheng1022 at gmail dot com
 Summary:            Fails if named parameters appears more than once
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            PDO related
 Operating System:   Mac OS X
 PHP Version:        5.5.0RC1
 Block user comment: N
 Private report:     N

 New Comment:

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Of course it fails. PDO just stinks: the core will replace :search with ?, then 
pass it to MySQL which expects two values for two placeholders. 

Can't work with the current PDO architecture. IMHO not a MySQL issue but yet 
another bug in the PDO architecture: you can't mess around with query 
manipulation at two layers that are logically seperated.


Previous Comments:
------------------------------------------------------------------------
[2013-05-18 03:31:28] zuohaocheng1022 at gmail dot com

Description:
------------
Pdo-mysql prepared statements execution fails when one named parameter appears 
more than once in a SQL statement. 

This problem will disappear if set PDO::ATTR_EMULATE_PREPARES to true.

Test script:
---------------
//CREATE TABLE `posts` (
//  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
//  `name` VARCHAR(255),
//  `body` TEXT
//);

$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

// :search appears twice here
$stmt = $pdo->prepare('SELECT id FROM posts WHERE name LIKE :search OR body 
LIKE :search'); 
$s = 'blablah';
$stmt->bindParam(':search', $s);
$stmt->execute(); // This step throws an exception: Error: SQLSTATE[HY093]: 
Invalid parameter number
// $stmt->execute([':search'=>$s]); will throw it too
$result = $stmt->fetch();

Expected result:
----------------
No exceptions.

Actual result:
--------------
$stmt>execute fails.

Error: SQLSTATE[HY093]: Invalid parameter number



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



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=64875&edit=1

Reply via email to