php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41868 Error with multiple instances of same named parameter
Submitted: 2007-07-02 05:10 UTC Modified: 2007-07-03 23:42 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: nick+phpbugs at ag dot arizona dot edu Assigned: iliaa (profile)
Status: Not a bug Package: PDO related
PHP Version: 5.2.3 OS: Linux
Private report: No CVE-ID: None
 [2007-07-02 05:10 UTC] 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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-02 19:51 UTC] jay at mysql dot com
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
 [2007-07-03 23:42 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Mar 03 03:01:24 2021 UTC