php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42113 Problem with placeholders and escaped quotes in string constants
Submitted: 2007-07-26 16:03 UTC Modified: 2007-07-28 09:16 UTC
From: dominique dot archambault at gmail dot com Assigned:
Status: Closed Package: PDO related
PHP Version: 5.2.3 OS: Debian lenny
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dominique dot archambault at gmail dot com
New email:
PHP Version: OS:

 

 [2007-07-26 16:03 UTC] dominique dot archambault at gmail dot com
Description:
------------
Using PHP 5.2.3 and MySQL 5.0.38.

If there are placeholders in string constants of an SQL query, and there are also escaped quotes in a string constant (either the same string constant, or a different one), the following error is triggered:

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: no parameters were bound in <FILE> on line <LINE>


Reproduce code:
---------------
// WORKS
$stmt = $pdo->prepare("SELECT * FROM `test` WHERE `test`.`text` = \"Hello world's! 2007-01-01 00:00:00\"");
if ($stmt->execute()) {
   print "PASSED!\n";
} else {
   // should not enter this
   print "FAILED!\n";
   var_dump($stmt->errorInfo());
}

// DOES NOT WORK
$stmt = $pdo->prepare("SELECT * FROM `test` WHERE `test`.`text` = 'Hello world\'s! 2007-01-01 00:00:00'");
// the following execute() call will generate the error
if ($stmt->execute()) {
   print "PASSED!\n";
} else {
   // will always enter this
   print "FAILED!\n";
   var_dump($stmt->errorInfo()); // will contain: array(1) { [0]=> string(5) "HY093" }
}


Expected result:
----------------
PASSED!
PASSED!


Actual result:
--------------
PASSED!

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: no parameters were bound in <FILE> on line <LINE>
FAILED!
array(1) {
  [0]=>
  string(5) "HY093"
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-27 18:42 UTC] dominique dot archambault at gmail dot com
The CVS snapshot (5.2.4) worked and my test case ran flawlessly! It would seem the bug was addressed and corrected.

Only have to wait for the official release of 5.2.4 :) Thank you very much!
 [2007-07-28 09:16 UTC] johannes@php.net
Then it's closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 23 03:01:28 2024 UTC