#47977 [Opn->Fbk]: bindParam, current(), next()
| From: | jani@php.net | Date: | Thu, 30 Apr 2009 10:47:05 +0000 |
| Subject: | #47977 [Opn->Fbk]: bindParam, current(), next() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-136561@lists.php.net to get a copy of this message | ||
ID: 47977
Updated by: jani@php.net
Reported By: fhgvbrdyftgjhgtfr at gazeta dot pl
-Status: Open
+Status: Feedback
Bug Type: PDO related
Operating System: Unix
PHP Version: 5.2.9
New Comment:
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves.
A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external
resources such as databases, etc. If the script requires a
database to demonstrate the issue, please make sure it creates
all necessary tables, stored procedures etc.
Please avoid embedding huge scripts into the report.
Previous Comments:
------------------------------------------------------------------------
[2009-04-16 00:22:47] fhgvbrdyftgjhgtfr at gazeta dot pl
Description:
------------
bindParam doesn't work with vars returned by current(), next()
Reproduce code:
---------------
<?php
$array = array_diff($array2, array_keys($array3));
reset($array);
$size = count($array);
$in = '?';
for($i = 1; $i < $size; ++$i) $in .= ', ?';
$stmt = $db->prepare('SELECT
name FROM table WHERE
language = ?
AND code IN('.$in.')');
$stmt->bindValue(1, 'en', PDO::PARAM_STR, 2);
$i = 1;
$element = current($array);
do {
$stmt->bindParam(++$i, $element, PDO::PARAM_STR, 2);
} while(($element = next($array)) !== false);
Expected result:
----------------
SELECT name FROM table WHERE language = 'en' AND
code IN('us',
'gb', 'nz')
Actual result:
--------------
SELECT name FROM table WHERE language = 'en' AND
code IN('0',
'0', '0')
When i change
$stmt->bindParam(++$i, $element, PDO::PARAM_STR, 2);
to
$stmt->bindValue(++$i, $element, PDO::PARAM_STR, 2);
i get:
SELECT name FROM table WHERE language = 'en' AND
code IN('us',
'gb', 'nz')
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=47977&edit=1