#41868 [Com]: Error with multiple instances of same named parameter
| From: | jay at mysql dot com | Date: | Mon, 02 Jul 2007 19:51:54 +0000 |
| Subject: | #41868 [Com]: Error with multiple instances of same named parameter | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-114548@lists.php.net to get a copy of this message | ||
ID: 41868
Comment by: jay at mysql dot com
Reported By: nick+phpbugs at ag dot arizona dot edu
Status: Open
Bug Type: PDO related
Operating System: Linux
PHP Version: 5.2.3
New Comment:
This was unsupported behaviour and only worked by accident before
5.2.1. Use bindValue() instead. For more information, see here:
http://paul-m-jones.com/blog/?p=243
Cheers,
Jay
Previous Comments:
------------------------------------------------------------------------
[2007-07-02 05:10:28] nick+phpbugs at ag dot arizona dot edu
Description:
------------
A named parameter should be able to be included more than once in a
query, but bound only once. Instead, when code like the given is
executed, the following error is produced:
Warning: PDOStatement::execute() [function.PDOStatement-execute]:
SQLSTATE[HY093]: Invalid parameter number: number of bound variables
does not match number of tokens in /home/njm/public_html/test.php on
line 7
Reproduce code:
---------------
$db = new PDO('mysql:host=localhost;dbname=test', 'test', 'whatever');
$db->exec('CREATE TABLE foo (a INT, b INT)');
$sth = $db->prepare('INSERT INTO foo (a, b) VALUES (:value, :value)');
$sth->bindParam(':value', 10);
$sth->execute();
Expected result:
----------------
A row inserted into foo where a = b = 10.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=41868&edit=1