ID: 41622
User updated by: andrea dot spacca at gmail dot com
Reported By: andrea dot spacca at gmail dot com
Status: Open
Bug Type: PDO related
Operating System: Linux
PHP Version: 5.2.3
New Comment:
in expected result the var_dumped array should be:
array(1) {
[0]=>
array(2) {
["field"]=>
string(1) "1"
[0]=>
string(1) "1"
}
}
Previous Comments:
------------------------------------------------------------------------
[2007-06-07 09:53:44] andrea dot spacca at gmail dot com
Description:
------------
Binding params to placeholders in prepared query don't work
(i tested the script both cli and in apache enviroment)
[pdo_mysql]
PDO Driver for MySQL, client library version => 5.0.34
[pdo_sqlite]
PDO Driver for SQLite 3.x => enabled
PECL Module version => 1.0.1
SQLite Library => 3.3.17
Reproduce code:
---------------
try {
$sql = 'SELECT field FROM table WHERE field = :placeholder
LIMIT 0, 1';
$db = new PDO([...]);
$tmp = $db->prepare($sql);
$tmp->execute(array(':placeholder' => 1));
var_dump($tmp->queryString);
var_dump($tmp->fetchAll());
$db = NULL;
} catch (Exception $e) {
var_dump($e);
}
Expected result:
----------------
$tmp->queryString should contain the :placeholder binded to the value
passed in execute(), and (as far as the query will produce row result
from the db) $tmp->fetchAll() should contain the resulted row
expected output:
string(61) "SELECT field FROM table WHERE field = 1 LIMIT 0, 1"
array(1) {
[0]=>
array(2) {
["field"]=>
string(1) "1"
[0]=>
string(1) "1"
["urlString"]=>
string(44) "http://comequandofuoripiove.leonardo.it/foto"
[1]=>
string(44) "http://comequandofuoripiove.leonardo.it/foto"
["scheme"]=>
string(4) "http"
[2]=>
string(4) "http"
["dominio"]=>
string(32) "comequandofuoripiove.leonardo.it"
[3]=>
string(32) "comequandofuoripiove.leonardo.it"
["insertTimestamp"]=>
string(13) "1177596562453"
[4]=>
string(13) "1177596562453"
["diffChk"]=>
string(1) "1"
[5]=>
string(1) "1"
}
}
Actual result:
--------------
$tmp->quetryString haven't the :placeholder binded to the value passed
in execute(), so the query won't be a valid one and $tmp->fetchAll()
will be empty
the same happens using PDOStatement::bindValue() or
PDOStatement::bindParam()
the result seems not being related to a specific db driver (i tested
with mysql and sqlite)
no exception is raised
script output:
string(61) "SELECT * FROM table WHERE field = :placeholder"
array(0) {
}
ps: if i remove the placeholder from prepare() and then try to still
bind a value in execute() an exception is raised: "SQLSTATE[HY000]:
General error: 25 bind or column index out of range"
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=41622&edit=1