#41971 [Opn->Csd]: PDOStatement::fetch and PDOStatement::setFetchMode causes unexpected behavior
| From: | iliaa@php.net | Date: | Tue, 31 Jul 2007 22:48:51 +0000 |
| Subject: | #41971 [Opn->Csd]: PDOStatement::fetch and PDOStatement::setFetchMode causes unexpected behavior | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-115617@lists.php.net to get a copy of this message | ||
ID: 41971
Updated by: iliaa@php.net
Reported By: joelboh at gmail dot com
-Status: Open
+Status: Closed
Bug Type: PDO related
Operating System: Linux
PHP Version: 5.2CVS-2007-07-12
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2007-07-12 13:29:52] joelboh at gmail dot com
No change in the result, $obj is still false with snapshot:
php5.2-200707121230
------------------------------------------------------------------------
[2007-07-12 11:42:19] jani@php.net
Please try using this CVS snapshot:
http://snaps.php.net/php5.2-latest.tar.gz
For Windows (zip):
http://snaps.php.net/win32/php5.2-win32-latest.zip
For Windows (installer):
http://snaps.php.net/win32/php5.2-win32-installer-latest.msi
------------------------------------------------------------------------
[2007-07-11 23:20:30] joelboh at gmail dot com
Description:
------------
When using PDOStatement::setFetchMode() with PDO::FETCH_CLASS and
PDO::FETCH_PROPS_LATE a call without arguments to PDOStatement::fetch()
wont work.
Reproduce code:
---------------
<?php
class Person
{
public $parameter;
public function __construct($parameter)
{
$this->parameter = $parameter;
}
}
$db = new PDO("sqlite::memory:");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->exec("CREATE TABLE person (id INTEGER NOT NULL, name
varchar(100))");
$db->exec("INSERT INTO person(id, name) VALUES (1, 'Sven')");
$stmt = $db->query('SELECT * FROM person');
$stmt->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Person',
array(0 => 'Parameter'));
/* To get the expected result you must use:
$stmt->fetch(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE);
Should that really be needed? */
$obj = $stmt->fetch();
print_r($obj);
Expected result:
----------------
Person Object ( [parameter] => Parameter [id] => 1 [name] => Sven )
Actual result:
--------------
$obj is false
If PDO::FETCH_PROPS_LATE is not used in PDOStatement::setFetchMode and
PDOStatement::fetch() is called without arguments you get the expected
result.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=41971&edit=1