php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44327 PDORow::queryString property & numeric offsets / Crash
Submitted: 2008-03-04 17:21 UTC Modified: 2008-11-03 16:07 UTC
From: uwendel at mysql dot com Assigned: felipe (profile)
Status: Closed Package: PDO related
PHP Version: 5.3CVS-2008-03-04 (snap) OS: Linux
Private report: No CVE-ID: None
 [2008-03-04 17:21 UTC] uwendel at mysql dot com
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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-14 09:03 UTC] uwendel at mysql dot com
Crash with CVS snapshot


nixnutz@ulflinux:~/php53_libmysql> sapi/cli/php -v
PHP 5.3.0-dev (cli) (built: Apr 11 2008 12:02:49)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2008 Zend Technologies

nixnutz@ulflinux:~/php53_libmysql> sapi/cli/php -r '$db = new PDO("sqlite:/tmp/foo"); $stmt = $db->query("SELECT 1"); $row = $stmt->fetch(PDO::FETCH_LAZY);  var_dump($row->{0}); var_dump($row->queryString); get_class($row);'
string(1) "1"
string(1) "1"
Speicherzugriffsfehler
 [2008-04-14 09:06 UTC] uwendel at mysql dot com
Adding "Crash" to Summary.
 [2008-07-04 17:12 UTC] uw@php.net
Part one of my report is bogus and the crash seems to be gone. Can anybody verify and close it?
 [2008-11-03 16:07 UTC] felipe@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC