note 113922 added to function.pg-query

From: Date: Tue, 17 Dec 2013 22:00:24 +0000
Subject: note 113922 added to function.pg-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-197964@lists.php.net to get a copy of this message
Here is my small function to make it easier for me to use data from select queries (attention, it is sensitive to sql injection) <?php function requestToDB($connection,$request){ if(!$result=pg_query($connection,$request)){ return False; } $combined=array(); while ($row = pg_fetch_assoc($result)) { $combined[]=$row; } return $combined; } ?> Example: <?php $conn = pg_pconnect("dbname=mydatabase"); $results=requestToDB($connect,"select * from mytable"); //You can now access a "cell" of your table like this: $rownumber=0; $columname="mycolumn"; $mycell=$results[$rownumber][$columname]; var_dump($mycell); ---- Server IP: 72.52.91.14 Probable Submitter: 72.52.91.14 ---- Manual Page -- http://php.net/manual/en/function.pg-query.php Edit -- https://master.php.net/note/edit/113922 Del: integrated -- https://master.php.net/note/delete/113922/integrated Del: useless -- https://master.php.net/note/delete/113922/useless Del: bad code -- https://master.php.net/note/delete/113922/bad+code Del: spam -- https://master.php.net/note/delete/113922/spam Del: non-english -- https://master.php.net/note/delete/113922/non-english Del: in docs -- https://master.php.net/note/delete/113922/in+docs Del: other reasons-- https://master.php.net/note/delete/113922 Reject -- https://master.php.net/note/reject/113922 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#197964) next »