Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

// free the result and close the connection
pg_freeresult($Result);
pg_close($Connection);
?>


array pg_fetch_array(integer result, integer row)


The pg_fetch_array function returns an array containing every field value for the given
row. The values are indexed by number, starting with zero, and by column name. Each
call to pg_fetch_array returns the next row, or FALSE when no rows remain. Compare
this function to pg_fetch_object and pg_fetch_row.


<?
//connect to database
if(!($Connection = pg_connect("", "", "", "", "leon")))
{
print("Could not establish connection.
\n");
exit;
}


//create query
$Query = "SELECT * ";
$Query .= "FROM item";


//execute query
if(!($Result = pg_exec($Connection, $Query)))
{
print("Could not execute query: ");
print(pg_errormessage($Connection));
print("
\n");
exit;
}


//loop over each row
while($Row = pg_fetch_array($Result, $Row))
{
print($Row["Name"]. "
\n");
}


// free the result and close the connection
pg_freeresult($Result);
pg_close($Connection);
?>


object pg_fetch_object(integer result, integer row)


The pg_fetch_object function returns an object with a property for every field. Each
property is named after the field name. Each call to pg_fetch_object returns the next

Free download pdf