|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-06-07 09:53 UTC] 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"
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 13:00:01 2025 UTC |
in expected result the var_dumped array should be: array(1) { [0]=> array(2) { ["field"]=> string(1) "1" [0]=> string(1) "1" } }