Bug #64953 [Opn->Ana]: Postgres prepared statement positional parameter casting
| From: | mike@php.net | Date: | Tue, 20 Aug 2013 13:07:08 +0000 |
| Subject: | Bug #64953 [Opn->Ana]: Postgres prepared statement positional parameter casting | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-181046@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=64953&edit=1
ID: 64953
Updated by: mike@php.net
Reported by: goetas at lignano dot it
Summary: Postgres prepared statement positional parameter
casting
-Status: Open
+Status: Analyzed
Type: Bug
Package: PDO related
Operating System: ubuntu 10.04
PHP Version: 5.3.25
Block user comment: N
Private report: N
New Comment:
The problem rather is, that PDO contains an SQL parser (or, erm, such) which
implements named parameters like ":argname". The result is then discovered by
people not only using MySQL: havoc.
Previous Comments:
------------------------------------------------------------------------
[2013-05-31 09:46:44] goetas at lignano dot it
Description:
------------
Using a prepared statement with positional parameters will produce unexpected behaviour when casting
these parameters.
Test script:
---------------
// pdo
$pdo = new \PDO("pgsql:host=localhost;dbname=db", "user", "pwd");
$pdo->setAttribute (\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$st = $pdo->prepare('SELECT ?::char as i');
$st->bindValue(1, '1');
$st->execute();
var_dump($st->fetch()); // return false
$st = $pdo->prepare('SELECT (?)::char as i');
$st->bindValue(1, '1');
$st->execute();
var_dump($st->fetch()); // return array(1) { ["i"]=> string(1) "1" }
// old pg extension
$dbconn = pg_connect("host=localhost dbname=superdpi user=postgres password=df54tb70");
$result = pg_prepare($dbconn, "my_query", 'SELECT $1::char as i');
$result = pg_execute($dbconn, "my_query", array("1"));
var_dump(pg_fetch_assoc ( $result)); // return array(1) { ["i"]=> string(1)
"1" }
Expected result:
----------------
array(2) {
["i"]=>
string(1) "1"
[0]=>
string(1) "1"
}
array(2) {
["i"]=>
string(1) "1"
[0]=>
string(1) "1"
}
array(1) {
["i"]=>
string(1) "1"
}
Actual result:
--------------
bool(false)
array(2) {
["i"]=>
string(1) "1"
[0]=>
string(1) "1"
}
array(1) {
["i"]=>
string(1) "1"
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64953&edit=1