Edit report at https://bugs.php.net/bug.php?id=60515&edit=1
ID: 60515
Comment by: jeffvanb at u dot washington dot edu
Reported by: phoenixseve at freenet dot de
Summary: "Invalid parameter number" although it is correct
Status: Open
Type: Bug
Package: PDO related
Operating System: archlinux x86_64
PHP Version: 5.3.8
Block user comment: N
Private report: N
New Comment:
This misleading error message is also thrown when you include a single-line
comment that contains a single-quote.
Example:
SELECT something
-- This valid SQL syntax shouldn't be a problem
FROM somewhere
WHERE value = :v;
PDO will tell you the parameter count is mismatched and you will pull your hair
out wondering what is wrong.
Previous Comments:
------------------------------------------------------------------------
[2011-12-13 20:57:47] phoenixseve at freenet dot de
Description:
------------
When I execute the attached test script an exception is thrown with the message:
SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not
match number of tokens
The exception is raised in the execute() line.
If you change the WHERE clause to `id`=24 there is no error message.
The same is true for this query: UPDATE `edtable` SET `id`=:p0 WHERE `id`='24'
The generated error message is obviously not correct. I don't even see why an
error message is generated as the request seems valid (although strange) to me.
Test script:
---------------
$createTableSql = <<<'EOT'
DROP TABLE IF EXISTS `edtable`;
CREATE TABLE IF NOT EXISTS `edtable` (
`id` bigint(20) NOT NULL,
`coun't()` varchar(20) NOT NULL
);
EOT;
$pdo = new PDO('mysql:host=localhost;dbname=aynte','aynte','aynte');
$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$result = $pdo->query($createTableSql);
$result->closeCursor();
$stmt = $pdo->prepare("UPDATE `edtable` SET `id`=:p0, `coun't()`= :p1 WHERE
`id`='24'");
$stmt->execute(array(':p0'=>'2', ':p1'=>'b2' ));
Expected result:
----------------
No error message.
Actual result:
--------------
PHP Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not
match number of tokens' in /srv/http/test.php:19\nStack trace:\n#0
/srv/http/test.php(19): PDOStatement->execute(Array)\n#1 {main}\n thrown in
/srv/http/test.php on line 19
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60515&edit=1