Re: first steps in PhP and PostgreSQL

From: Richard Huxton <dev(at)archonet(dot)com>
To: Desmond Coughlan <coughlandesmond(at)yahoo(dot)fr>
Cc: pgsql mailing list <pgsql-general(at)postgresql(dot)org>
Subject: Re: first steps in PhP and PostgreSQL
Date: 2006-11-06 14:42:15
Message-ID: 454F49C7.9010203@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Desmond Coughlan wrote:
> <?php
> pg_connect ("dbname=cdi user=cdi password=toto") or die
> ("Couldn't Connect: ".pg_last_error());
> $query="SELECT * FROM stock";
> $query=pg_query($query);

Firstly, rewrite this as
$sql = "SELECT * FROM stock";
$res = pg_query($sql);

echo "pg_query($sql) = $res<br>";
echo "num rows = ".pg_num_rows($res)."<br>";

> // start the output
> while($row=pg_fetch_array($query,NULL,PGSQL_ASSOC)) {
> echo "Title: ".$row['isbn_no']."<br />";
> echo "blah ".$row['code_livre']."<br />";
> }
> ?>

Now you'll know what the return-code of pg_query was as well as how manu
rows it returned. Does that help at all?

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Broersma Jr 2006-11-06 14:48:22 Re: select result / functions from another database in plpgsql
Previous Message Tom Lane 2006-11-06 14:42:03 Re: DISTINCT is not quite distinct