php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61327 PDO complain about Invalid parameter number
Submitted: 2012-03-08 15:27 UTC Modified: 2016-08-21 04:22 UTC
Votes:6
Avg. Score:4.3 ± 0.9
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:2 (50.0%)
From: daniel dot caillibaud at sesamath dot net Assigned: cmb (profile)
Status: No Feedback Package: PDO Core
PHP Version: 5.3.10 OS: linux
Private report: No CVE-ID: None
 [2012-03-08 15:27 UTC] daniel dot caillibaud at sesamath dot net
Description:
------------
The query 

INSERT INTO $table VALUES (\"first value\");
-- dam'd quote
INSERT INTO $table VALUES (\"foo : ba'r \"), 
(\"foo.:bar\");

Throws 
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: no parameters were bound

But doesn't
- without first query before comment
- without comment
- with escaped quote
- with space after last colon

Test script:
---------------
// This query doesn't work
$q1 = "INSERT INTO $table VALUES (\"first value\");
-- dam'd quote
INSERT INTO $table VALUES (\"foo : ba'r \"), 
(\"foo.:bar\"); ";
// But all these doesn't have any pb
$q2 = "-- dam'd quote         
INSERT INTO $table VALUES (\"foo : ba'r \"),                               
(\"foo.:bar\"); "; // without first one (before comment)
$q3 = "INSERT INTO $table VALUES (\"first value\");                             
INSERT INTO $table VALUES (\"foo : ba'r \"),                               
(\"foo.:bar\"); "; // without comment
$q4 = "INSERT INTO $table VALUES (\"first value\");                             
-- dam'd quote         
INSERT INTO $table VALUES (\"foo : ba\'r \"),
(\"foo.:bar\"); "; // with escaped quote
$q5 = "INSERT INTO $table VALUES (\"first value\");                             
-- dam'd quote         
INSERT INTO $table VALUES (\"foo : ba'r \"),                               
(\"foo.: bar\"); "; // with space after last colon

try {
  $pdo = new PDO($dsn, $user, $pass, $options);
  $stmt = $pdo->prepare($query);
  $stmt->execute();
}
catch (Exception $e) {
  echo "Failed : " .$e->getMessage();
}


Expected result:
----------------
No warning

Actual result:
--------------
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: no parameters were bound

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-01-01 12:40 UTC] felipe@php.net
-Package: PDO related +Package: PDO Core
 [2016-08-08 17:43 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2016-08-08 17:43 UTC] cmb@php.net
This doesn't appear to be a general PDO problem; at least I can't
reproduce it with pdo_sqlite, see <https://3v4l.org/64MQv>.

So if this problem persists with current PHP versions, we need
more specific information to be able to address the issue.
 [2016-08-21 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 13:01:30 2024 UTC