From: uwendel at mysql dot com
Operating system: Linux
PHP version: 5.3CVS-2008-03-04 (snap)
PHP Bug Type: PDO related
Bug description: PDORow::queryString property & numeric offsets
Description:
------------
What kind of thing is the PDORow::queryString property?
PDORow objects are generated and returned by
PDOStatement::fetch(PDO::FETCH_LAZY). PDORow objects seem a bit special in
some ways.
1) "PDO::FETCH_LAZY = PDO::FETCH_OBJ + PDO::FETCH_BOTH"
PDO::FETCH_BOTH means that the returned data is both indexed by the column
name and a column offset number. For example, a query like SELECT id FROM
test should return an object (resp. array) with the properties {0} and id.
You can access both properties and you get what you want. But var_dump()
will report only the column name based property and not the property based
on the numeric column offset.
I have no idea if this is a var_dump() or a PDO flaw.
2) The magic queryString property
var_dump() reports a queryString property for PDORow objects returned by
PDOStatement::fetch(). In all my testing I found the queryString propery
value to be the query string which has constructed the corresponding
PDOStatement object. However, I cannot access this property. I see it, but
I have no access. That makes it a bit "magic".
Also, note how var_dump(), var_export() and debug_zval_dump report
different things. Johannes already explained to me that the functions might
do different things, but anyway it looks confusing to me.
Reproduce code:
---------------
------------------------ 1, FETCH_LAZY and numeric offset ----------
sapi/cli/php -r '$db = new
PDO("mysql:dbname=phptest;unix_socket=/tmp/mysql.sock", "root", "root");
$stmt = $db->prepare("SELECT 1 AS \"one\""); $stmt->execute(); $row =
$stmt->fetch(PDO::FETCH_LAZY); var_dump($row); var_dump($row->{0});
var_dump($row->one); '
object(PDORow)#3 (2) {
["queryString"]=>
string(17) "SELECT 1 AS "one""
["one"]=>
string(1) "1"
}
-->
string(1) "1"
string(1) "1"
-------------------- 2, magic PDORow::queryString() ---------
sapi/cli/php -r '$db = new
PDO("mysql:dbname=phptest;unix_socket=/tmp/mysql.sock", "root", "root");
$stmt = $db->prepare("SELECT 1 AS \"one\""); $stmt->execute(); $row =
$stmt->fetch(PDO::FETCH_LAZY); var_dump($row); var_dump($row->queryString);
'
object(PDORow)#3 (2) {
["queryString"]=>
string(17) "SELECT 1 AS "one""
["one"]=>
string(1) "1"
}
-->
UNKNOWN:0
sapi/cli/php -r '$db = new
PDO("mysql:dbname=phptest;unix_socket=/tmp/mysql.sock", "root", "root");
$db->exec("DROP TABLE test"); $db->exec("CREATE TABLE test (id INT)");
$db->exec("INSERT INTO test(id) VALUES (1)"); $stmt = $db->prepare("SELECT
id FROM test"); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_LAZY);
var_dump($row); var_dump($row->queryString); var_export($row->queryString);
print "\n"; debug_zval_dump($row->queryString);'
-->
UNKNOWN:0
NULL
UNKNOWN:0
--
Edit bug report at http://bugs.php.net/?id=44327&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=44327&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=44327&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=44327&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=44327&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=44327&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=44327&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=44327&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=44327&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=44327&r=support
Expected behavior: http://bugs.php.net/fix.php?id=44327&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=44327&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=44327&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=44327&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=44327&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=44327&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=44327&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=44327&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=44327&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=44327&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=44327&r=mysqlcfg