note 115769 added to pdostatement.fetch

From: Date: Fri, 19 Sep 2014 12:41:17 +0000
Subject: note 115769 added to pdostatement.fetch
Groups: php.notes 
Request: Send a blank email to php-notes+get-200488@lists.php.net to get a copy of this message
Note that this way, the "fetch mode" will get "overwritten", and PDO::FETCH_PROPS_LATE won't be applied: <?php $sth = $db->prepare("SELECT * FROM user WHERE id = 1"); $sth->setFetchMode( PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE, 'user'); $sth->execute(); $user = $sth->fetch( PDO::FETCH_CLASS ); $sth->closeCursor(); ?> Instead, you should leave the parameter area for the fetch() method empty, like this (if you want to set the fetch mode with the setFetchMode() method): <?php $sth = $db->prepare("SELECT * FROM user WHERE id = 1"); $sth->setFetchMode( PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE, 'user'); $sth->execute(); $user = $sth->fetch(); $sth->closeCursor(); ?> ---- Server IP: 72.52.91.14 Probable Submitter: 92.37.63.117 ---- Manual Page -- http://php.net/manual/en/pdostatement.fetch.php Edit -- https://master.php.net/note/edit/115769 Del: integrated -- https://master.php.net/note/delete/115769/integrated Del: useless -- https://master.php.net/note/delete/115769/useless Del: bad code -- https://master.php.net/note/delete/115769/bad+code Del: spam -- https://master.php.net/note/delete/115769/spam Del: non-english -- https://master.php.net/note/delete/115769/non-english Del: in docs -- https://master.php.net/note/delete/115769/in+docs Del: other reasons-- https://master.php.net/note/delete/115769 Reject -- https://master.php.net/note/reject/115769 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#200488) next »