php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33886 PDO Prepared Statement fails if binding id (:blah) is used more then once.
Submitted: 2005-07-27 15:57 UTC Modified: 2005-07-27 16:20 UTC
Votes:31
Avg. Score:4.2 ± 1.1
Reproduced:22 of 25 (88.0%)
Same Version:4 (18.2%)
Same OS:5 (22.7%)
From: wb at pro-net dot co dot uk Assigned:
Status: Wont fix Package: PDO related
PHP Version: 5.0.4 OS: FreeBSD 5.4-RELEASE-p2
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2005-07-27 15:57 UTC] wb at pro-net dot co dot uk
Description:
------------
When using the same binding id in a query the PDOStatement::execute() method still requires you to specify the same amount of parameters.

Reproduce code:
---------------
<?php
$pdo = new PDO('pgsql:host=localhost dbname=bats user=user password=pass');
$pdo->setAttribute(PDO_ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION);

$statement = $pdo->prepare("
            UPDATE groups
            SET
               lft = CASE WHEN lft > :right
                     THEN lft + 2
                     ELSE lft END,
               rgt = CASE WHEN rgt >= :right
                     THEN rgt + 2
                     ELSE rgt END
            WHERE
              rgt >= :right
            ");
$statement->execute(array(':right' => 5));

?>

Expected result:
----------------
Would expect the statement to execute without issue.

Actual result:
--------------
PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[08P01]: <<Unknown error>>: 7 ERROR:  bind message supplies 1 parameters, but prepared statement "pdo_pgsql_stmt_08257c0c" requires 3' in /usr/home/wb/bats/scripts/tests/pdoQuery.php:17
Stack trace:
#0 /usr/home/wb/bats/scripts/tests/pdoQuery.php(17): PDOStatement->execute(Array)
#1 {main}
  thrown in /usr/home/wb/bats/scripts/tests/pdoQuery.php on line 17


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-27 16:00 UTC] wb at pro-net dot co dot uk
Using PDO-0.9 and PDO_PGSQL-0.9
 [2005-07-27 16:04 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2005-07-27 16:13 UTC] wez@php.net
It's not portable to rely on that.
You need to create three parameters and bind them separately.
 [2005-07-27 16:20 UTC] wb at pro-net dot co dot uk
Fair enougth.

I will submit a note to the php manual about this.

Keep up the good work :)
 [2014-03-18 15:53 UTC] php at pineight dot com
Use of named placeholders is also not portable, as MySQL supports only positional placeholders, yet PDO emulates it. Why does PDO emulate named placeholders on MySQL but not emulate repeated placeholders? Otherwise, applications using PDO will end up littered with passive-aggressive workarounds:

  $args[':skuid_bug33886'] = $args[':skuid'];
  $args[':supplierid_bug33886'] = $args[':supplierid'];
 [2016-03-21 14:07 UTC] leif at neland dot dk
Would

$statement = $pdo->prepare("
    SET @sql_param=:php_param;
    SELECT ... FROM TAB where p=@sql_param or q=@sql_param
");
$statement->execute(array(':php_param' => $php_variable));


work?
 [2023-09-06 01:50 UTC] egilmoreno at gmail dot com
Please, solution for this error:
<br />
<b>Fatal error</b>:  Uncaught PDOException: SQLSTATE[01000]: Warning: 1265 Data truncated for column 'id_client_user' at row 1 in /home/sidecil/subdominios/cloud/apirest/v1/models/post.model.php:37
Stack trace:
#0 /home/sidecil/subdominios/cloud/apirest/v1/models/post.model.php(37): PDOStatement-&gt;execute()
#1 /home/sidecil/subdominios/cloud/apirest/v1/controllers/post.controller.php(17): PostModel::postData('users', Array)
#2 /home/sidecil/subdominios/cloud/apirest/v1/routes/services/post.php(37): PostController::postData('users', Array)
#3 /home/sidecil/subdominios/cloud/apirest/v1/routes/routes.php(44): include('/home/sidecil/s...')
#4 /home/sidecil/subdominios/cloud/apirest/v1/controllers/routes.controller.php(11): include('/home/sidecil/s...')
#5 /home/sidecil/subdominios/cloud/apirest/v1/index.php(22): RoutesController-&gt;index()
#6 {main}
  thrown in <b>/home/sidecil/subdominios/cloud/apirest/v1/models/post.model.php</b> on line <b>37</b><br />
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 11:01:28 2024 UTC