php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51559 SQLSTATE[HY093]: Invalid parameter number (error in docs or calculation)
Submitted: 2010-04-15 11:30 UTC Modified: 2010-10-20 07:04 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: frode at seria dot no Assigned: kalle (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.2.13 OS: Debian Lenny
Private report: No CVE-ID: None
 [2010-04-15 11:30 UTC] frode at seria dot no
Description:
------------
I get the following PDOException when executing a prepared statement:
SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

This behaviour changed in PHP after version 5.2.0 and a related issue #40417 exists.

However, nothing in the documentation specifies that you can't bind MORE variables than are used in the SQL. For example if you call $statement->execute($_POST), you might bind more variables than are used in the SQL.

Test script:
---------------
$params = array(':key1' => 'value1', ':key2' => 'value2');
$stmt = $db->prepare('SELECT * FROM table WHERE id=:key1');
$stmt->execute($params);

Expected result:
----------------
I expect this to succeed. We relied on this feature in much of our old code working up to PHP version 5.2.0, but have made a workaround in our DB layer which parses the SQL.

Actual result:
--------------
PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-22 02:51 UTC] felipe@php.net
-Package: PDO related +Package: Documentation problem
 [2010-10-20 07:04 UTC] kalle@php.net
Automatic comment from SVN on behalf of kalle
Revision: http://svn.php.net/viewvc/?view=revision&revision=304528
Log: Fixed bug #51559 (SQLSTATE[HY093]: Invalid parameter number (error in docs or calculation))
 [2010-10-20 07:04 UTC] kalle@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: kalle
 [2010-10-20 07:04 UTC] kalle@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2020-02-07 06:09 UTC] phpdocbot@php.net
Automatic comment on behalf of kalle
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=2e76923470136294c53cb761ae0754ce334edf19
Log: Fixed bug #51559 (SQLSTATE[HY093]: Invalid parameter number (error in docs or calculation))
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 04:01:28 2024 UTC