|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-12-13 20:57 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 14:00:01 2025 UTC |
$stmt = $pdo->prepare("UPDATE `edtable` SET `id`=:p0, `coun't()`= :p1 WHERE `id`='24'"); Your SQL is invalid. Whatever is behind, parsing is done by the PDO core. Thus, this is most unlikely to be MySQL specific. Parsing needs to be done as a syntax is used that is not supported by MySQL. Replace MySQL here with any other DB that does not support named parameters or do the same with questionmarks and a DB that does support named parameters only but no questionmarks.