note 109545 modified in function.pg-fetch-object by danbrown

From: Date: Mon, 30 Jul 2012 15:50:48 +0000
Subject: note 109545 modified in function.pg-fetch-object by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189484@lists.php.net to get a copy of this message
Getting db results as object.&#13;&#10;&#13;&#10;&#60;?php&#13;&#10;$qry = pg_query(&#34;SELECT * FROM users&#34;);&#13;&#10;&#13;&#10;$rows = array();&#13;&#10;while ($fch = pg_fetch_object($qry)) {&#13;&#10; $rows[] = $fch;&#13;&#10;}&#13;&#10;&#13;&#10;// or&#13;&#10;&#13;&#10;$rows = array_map(function($a){&#13;&#10; return (object) $a;&#13;&#10;}, (array) pg_fetch_all($qry));&#13;&#10;?&#62; --was-- Getting db results as object. <?php $qry = pg_query("SELECT * FROM users"); $rows = array(); while ($fch = pg_fetch_object($qry)) { $rows[] = $fch; } // or $rows = array_map(function($a){ return (object) $a; }, (array) pg_fetch_all($qry)); http://php.net/manual/en/function.pg-fetch-object.php

« previous php.notes (#189484) next »