You are here: Home Development PHP PHP/PostgreSQL: Create Recordset & Display
PHP/PostgreSQL: Create Recordset & Display PDF Print E-mail
User Rating: / 0
PoorBest 
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);

Comments (0)
Write comment
Your Contact Details:
Gravatar enabled
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):S
:!::?::idea::arrow:
Security
Please input the anti-spam code that you can read in the image.