|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-07-12 11:42 UTC] jani@php.net
[2007-07-12 13:29 UTC] joelboh at gmail dot com
[2007-07-31 22:48 UTC] iliaa@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 14:00:01 2025 UTC |
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.