|
Development -
PHP
|
|
Written by Rick
|
|
Monday, 25 January 2010 12:00 |
|
Creating a recordset and displaying data from a PostgreSQL table using PHP;
Making the connection:
$DB_HOST="hostname"; $DB_NAME="databasename"; $DB_USER="username"; $DB_PASSWORD="password";
$psql="Select DISTINCT fieldname FROM table"; $const = "host=".$DB_HOST." dbname=".$DB_NAME." user=".$DB_USER." password=".$DB_PASSWORD.""; $pcon=pg_connect($const); if (!$pcon) { echo "<script type=\"text/javascript\">alert(\"Unable to connect to PostgreSQL Server!\")</script><script type=\"text/javascript\">history.back()</script>"; }else{ $getRS = pg_exec($pcon,$psql); }
pg_close($pcon);
Create the recordset and display:
$getRS = psqlSelectRS($psql); $rows=pg_num_rows($getRS);
for ($i=0; $i<$rows; $i++) { $row_getRS=pg_fetch_row($getRS, $i); echo "Row Value: ".$row_getRS[0]."<br />; }
pg_free_result($getRS);
|