simple db query function

Fred22

New Member
I want to be able to call a query function and based on the results they are put into an object that I can call outside the function. This is what I have:\[code\]<?phpfunction query($sql) {global $r;$database = "theatre";$db_conn = pg_connect ("host=localhost port=5432 dbname=$database user=postgres");if (!$db_conn): ?><h1>Failed connecting to postgres database <?php echo $database;?></h1> <?phpexit;endif;$ep = pg_query ($db_conn, $sql);while ($r = pg_fetch_object ($ep)) {}pg_free_result($ep);pg_close($db_conn);}query('select * from test');echo $r->fname;\[/code\]I don't want to hardcode any column names into the function. So fname is an example but it will be dynamic based on the query. I have a while loop but not sure what to put in it.
 
Back
Top