[OSGeo-Discuss] Db connect

Dave Patton davep at confluence.org
Wed Mar 3 17:13:24 PST 2010


On 2010/03/02 7:01 PM, Ravi wrote:
> Hi, am using OSGeo4W bundle and the apache and php there in. Apache
> installed OK showing as aservice and in the browser http:\\localhost 
> issues the OSGeo4w welcome screen and phpthere on
> 
> with the following wish to connect to PGSQL 8.4 and postGIS there in 
> with the following. But it doesnt work. Where am I going wrong ?
> 
> $db_handle = pg_connect(”host = localhost port = 5432 dbname =
> postgis user = postgres password = GrassJump”); $query = “SELECT *
> FROM rjybound”; $result = pgexec($dbhandle, $query);

Try something like this. (Not fully tested)

<?
error_reporting(E_ALL);
$db_handle = pg_connect("host = localhost port = 5432 dbname = postgis 
user = postgres password = GrassJump");
if( $db_handle === FALSE ) {
   echo 'Failed to connect';
} else {
   $query = 'SELECT * FROM rjybound';
   $result = pg_query($db_handle, $query);
   if( $result === FALSE ) {
     $error = pg_last_error($db_handle);
     if( $error === FALSE ) {
       echo 'Unable to determine last error';
     } else {
       echo 'Last Error = ' . $error;
     }
   } else {
     while ( $row = pg_fetch_row($result) ) {
       echo "Element 0: $row[0]";
       echo "<br />\n";
     }
   }
}
?>



-- 
Dave Patton
CIS Canadian Information Systems
Victoria, B.C.

Degree Confluence Project:
Canadian Coordinator
Technical Coordinator
http://www.confluence.org/

Personal website:
Maps, GPS, etc.
http://members.shaw.ca/davepatton/



More information about the Discuss mailing list