|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-03-11 16:00 UTC] robert dot allen at zircote dot com
Description: ------------ Windows XP / PHP 5.2.5 / PDO_ODBC When setFetchMode is called with FETCH_CLASS and the Object type specified the Object type is returned as stdClass in the array for fetchAll() however for fetch() returns the expected result of the defined object. Reproduce code: --------------- $stmt->setFetchMode(PDO :: FETCH_CLASS | PDO :: FETCH_CLASSTYPE, 'MyClass'); $stmt->execute(); $all = $stmt->fetchAll(); Expected result: ---------------- return: Array ( [0] => MyClass Object (..... Actual result: -------------- return: Array ( [0] => stdClass Object (..... PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 19 08:00:01 2025 UTC |
Server OS: Solaris 9, Database server: IBM Informix IDS 9.4, Web Server Apache/2.0.54, PHP: 5.2.5, ODBC-driver: IBM Informix ODBC Driver ------------------- Reproduce Code: class MyBaseClass { public $par1; private $par2; private $par3; public $par4; } class MyClass extends MyBaseClass { public $par5; public $par6; public function __construct($par1, $par4, $par5, $par6) { $this->par1 = $par1; $this->par2 = $par1; $this->par3 = $par4; $this->par4 = $par4; $this->par5 = $par5; $this->par6 = $par6; } } $db = new PDO("informix:connection string parameters", "user", "password"); $stmt = $db->prepare("EXECUTE PROCEDURE mystoredprocedure()"); $stmt->setFetchMode(PDO::FETCH_CLASS,'MyClass'); $stmt->execute(); $result = $stmt->fetchAll(PDO::FETCH_CLASS); print_r($result); ---------------------- Expected result: Array ( [0] => MyClass Object (... ------------------------------ Actual result: Array ( [0] => stdClass Object (...Just use PDO::FETCH_CLASS, the flag PDO::FETCH_CLASSTYPE does it works differently. As is mentioned in the source: "fetch class gets its class name from 1st column". Lets test it! mysql> create table testz (name varchar(200)); Query OK, 0 rows affected (0.00 sec) mysql> insert into testz values ('myclass'); Query OK, 1 row affected (0.00 sec) mysql> insert into testz values ('myclass2'); Query OK, 1 row affected (0.00 sec) class myclass { } class myclass2 { } $stmt->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE, 'myclass'); $stmt->execute(); $all = $stmt->fetchAll(); array(2) { [0]=> object(myclass)#3 (0) { } [1]=> object(myclass2)#4 (0) { } } Though currently the third parameter to setFetchMode is mandatory when using PDO::FETCH_CLASS, it seems incorret when using the flag FETCH_CLASSTYPE, as the class name come from a table column. And yes, this must be documented. Thanks. :)