Thread: first steps in PhP and PostgreSQL

first steps in PhP and PostgreSQL

From
Desmond Coughlan
Date:
X-No-Archive: true
 
Hi,
I'm sure that it's a typo or something, but as I'm getting into PhP and PostgreSQL for the first time, I can't be sure.
 
I have a db, called 'cdi' ..
 
A 'SELECT * FROM stock;' gets me this in psql ..
 
cdi=> SELECT * from stock ;
-[ RECORD 1 ]-+-------------------------------
stock_ids     | 1
isbn_no       | 10101010
code_livre    | 23455
titre         | toto goes to Hollywood
editeur       | editions toto
collection    | collection toto
auteur_nom    | smith
auteur_prenom | john
matiere       | ang
media_type    | li
-[ RECORD 2 ]-+-------------------------------
stock_ids     | 2
isbn_no       | 10536278
code_livre    | 24874
titre         | toto comes back from Hollywood
editeur       | editions baba
collection    | collection toto
auteur_nom    | martin
auteur_prenom | peter
matiere       | fre
media_type    | dvd

So the db is populated.  I now do this in a file called base.php ..
 
<?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);
// start the output
while($row=pg_fetch_array($query,NULL,PGSQL_ASSOC)) {
echo "Title: ".$row['isbn_no']."<br />";
echo "blah ".$row['code_livre']."<br />";
}
?>

 
I copy that file to my apache server, in php_experimental/base.php and access it via a browser.
 
I don't get an error message. I instead get a blank page.
 
Your advice would be welcome.
 
D.


Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses.

Re: first steps in PhP and PostgreSQL

From
Bill Moran
Date:
In response to Desmond Coughlan <coughlandesmond@yahoo.fr>:

> X-No-Archive: true

X-WTF: huh?

[snip]

>   I copy that file to my apache server, in php_experimental/base.php
> and access it via a browser.
>
>   I don't get an error message. I instead get a blank page.

Check the applicable php.ini for where error messages are being sent to.
It's typical on production servers to configure PHP to only send errors
to syslog, or a file, which usually means they end up in httpd-error.log.

When developing, it's usually more convenient to have errors sent to the
browser, which is what it seems you were expecting.

--
Bill Moran
Collaborative Fusion Inc.

Re: first steps in PhP and PostgreSQL

From
Roman Neuhauser
Date:
# coughlandesmond@yahoo.fr / 2006-11-06 15:05:25 +0100:
>   I'm sure that it's a typo or something, but as I'm getting into PhP
>   and PostgreSQL for the first time, I can't be sure.

>   <?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);
>   // start the output
>   while($row=pg_fetch_array($query,NULL,PGSQL_ASSOC)) {
> echo "Title: ".$row['isbn_no']."<br />";
> echo "blah ".$row['code_livre']."<br />";
> }
>   ?>
>
>   I copy that file to my apache server, in php_experimental/base.php
>   and access it via a browser.
>
>   I don't get an error message. I instead get a blank page.

    Check apache's error log. If you can't figure it out then, better
    place to ask further questions would be php-general@lists.php.net.

--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE.             http://bash.org/?255991

Re: first steps in PhP and PostgreSQL

From
Richard Huxton
Date:
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

Re: first steps in PhP and PostgreSQL

From
Ben
Date:
Have you checked your webserver error logs?

On Mon, 6 Nov 2006, Desmond Coughlan wrote:

> X-No-Archive: true
>
>  Hi,
>  I'm sure that it's a typo or something, but as I'm getting into PhP and PostgreSQL for the first time, I can't be
sure.
>
>  I have a db, called 'cdi' ..
>
>  A 'SELECT * FROM stock;' gets me this in psql ..
>
>  cdi=> SELECT * from stock ;
> -[ RECORD 1 ]-+-------------------------------
> stock_ids     | 1
> isbn_no       | 10101010
> code_livre    | 23455
> titre         | toto goes to Hollywood
> editeur       | editions toto
> collection    | collection toto
> auteur_nom    | smith
> auteur_prenom | john
> matiere       | ang
> media_type    | li
> -[ RECORD 2 ]-+-------------------------------
> stock_ids     | 2
> isbn_no       | 10536278
> code_livre    | 24874
> titre         | toto comes back from Hollywood
> editeur       | editions baba
> collection    | collection toto
> auteur_nom    | martin
> auteur_prenom | peter
> matiere       | fre
> media_type    | dvd
>
>  So the db is populated.  I now do this in a file called base.php ..
>
>  <?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);
>  // start the output
>  while($row=pg_fetch_array($query,NULL,PGSQL_ASSOC)) {
> echo "Title: ".$row['isbn_no']."<br />";
> echo "blah ".$row['code_livre']."<br />";
> }
>  ?>
>
>
>
>  I copy that file to my apache server, in php_experimental/base.php and access it via a browser.
>
>  I don't get an error message. I instead get a blank page.
>
>  Your advice would be welcome.
>
>  D.
>
>
> ---------------------------------
> Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! Profitez des connaissances, des opinions
etdes expériences des internautes sur Yahoo! Questions/Réponses. 

RE : Re: first steps in PhP and PostgreSQL

From
Desmond Coughlan
Date:
X-No-Archive: true
 
Yep...
 
192.168.0.254 - - [07/Nov/2006:10:12:57 +0100] "GET /php_experimental/base.php HTTP/1.1" 200 - "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
D.

Ben <bench@silentmedia.com> a écrit :
Have you checked your webserver error logs?

On Mon, 6 Nov 2006, Desmond Coughlan wrote:

> X-No-Archive: true
>
> Hi,
> I'm sure that it's a typo or something, but as I'm getting into PhP and PostgreSQL for the first time, I can't be sure.
>
> I have a db, called 'cdi' ..
>
> A 'SELECT * FROM stock;' gets me this in psql ..
>
> cdi=> SELECT * from stock ;
> -[ RECORD 1 ]-+-------------------------------
> stock_ids | 1
> isbn_no | 10101010
> code_livre | 23455
> titre | toto goes to Hollywood
> editeur | editions toto
> collection | collection toto
> auteur_nom | smith
> auteur_prenom | john
> matiere | ang
> media_type | li
> -[ RECORD 2 ]-+-------------------------------
> stock_ids | 2
> isbn_no | 10536278
> code_livre | 24874
> titre | toto comes back from Hollywood
> editeur | editions baba
> collection | collection toto
> auteur_nom | martin
> auteur_prenom | peter
> matiere | fre
> media_type | dvd
>
> So the db is populated. I now do this in a file called base.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);
> // start the output
> while($row=pg_fetch_array($query,NULL,PGSQL_ASSOC)) {
> echo "Title: ".$row['isbn_no']."
";
> echo "blah ".$row['code_livre']."
";
> }
> ?>
>
>
>
> I copy that file to my apache server, in php_experimental/base.php and access it via a browser.
>
> I don't get an error message. I instead get a blank page.
>
> Your advice would be welcome.
>
> D.
>
>
> ---------------------------------
> Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses.
---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly



--
Des Coughlan
"Un client de plus, c'est un relou de plus..."


Yahoo! Mail réinvente le mail ! Découvrez le nouveau Yahoo! Mail et son interface révolutionnaire.