Re: first steps in PhP and PostgreSQL - Mailing list pgsql-general

From Richard Huxton
Subject Re: first steps in PhP and PostgreSQL
Date
Msg-id 454F49C7.9010203@archonet.com
Whole thread Raw
In response to first steps in PhP and PostgreSQL  (Desmond Coughlan <coughlandesmond@yahoo.fr>)
List 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

pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: DISTINCT is not quite distinct
Next
From: Tom Lane
Date:
Subject: Re: DISTINCT is not quite distinct