note 79291 added to function.PDOStatement-setFetchMode

From: Date: Tue, 20 Nov 2007 00:04:24 +0000
Subject: note 79291 added to function.PDOStatement-setFetchMode
Groups: php.notes 
Request: Send a blank email to php-notes+get-132414@lists.php.net to get a copy of this message
Some note on PDO :: FETCH_CLASS | PDO :: FETCH_CLASSTYPE It took me some time, to realize, that you can not use this fetch-mode in $stm->setFetchMode(), when you want to retrieve objects from the database whereas the type is defined by the first column in the resultset. You have to define this mode directly in the $stm->fetch() method. To make it clearer: $stm = $pdo->query("SELECT * FROM foo); $stm->setFetchMode(FETCH_CLASS | PDO :: FETCH_CLASSTYPE); $object = $stm->fetch(); Will not return the expected object, whereas $stm = $pdo->query("SELECT * FROM foo"); $object = $stm->fetch(FETCH_CLASS | PDO :: FETCH_CLASSTYPE); will give you the object of the class, defined in the first column of foo. ---- Server IP: 69.147.83.197 Probable Submitter: 217.86.17.69 ---- Manual Page -- http://www.php.net/manual/en/function.PDOStatement-setFetchMode.php Edit -- https://master.php.net/note/edit/79291 Del: integrated -- https://master.php.net/note/delete/79291/integrated Del: useless -- https://master.php.net/note/delete/79291/useless Del: bad code -- https://master.php.net/note/delete/79291/bad+code Del: spam -- https://master.php.net/note/delete/79291/spam Del: non-english -- https://master.php.net/note/delete/79291/non-english Del: in docs -- https://master.php.net/note/delete/79291/in+docs Del: other reasons-- https://master.php.net/note/delete/79291 Reject -- https://master.php.net/note/reject/79291 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#132414) next »