PHP Postgresql Functions problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
gungfusteve
Forum Newbie
Posts: 1
Joined: Wed Jun 17, 2009 12:13 am

PHP Postgresql Functions problem

Post by gungfusteve »

Hi everyone, this is my first post. I am having trouble getting my postgresql 8.3 database to respond as desired when using php on my pc's apache server. The problem is that when I try to perform a query using pg_query() in my php code and then try using pg_fetch_row() on the resulting resource, the array that is returned is completely empty. However, whenever I use psql to enter the same query as what I entered using the php code, a table with a row is definitely shown. Here is the code I use in php to try to use an existing connection to get a row:

Code: Select all

 
if (pg_connection_status($connection)==PGSQL_CONNECTION_OK){
    $result = pg_query($connection, "select * from pg_tables where schemaname='public';");
    echo "<br />";
    $row = pg_fetch_row($result);
    echo "first cell: $row[0]";
    echo "$row[1]";
    echo "$row[2]";
    echo "$row[3]";
    echo "<br />";
    echo pg_last_error($connection);
}
If I use

Code: Select all

"select * from pg_tables where schemaname='public';"
in psql, it definitely shows an entry (the table i created in psql earlier).

I am definitely a beginner in both PHP and PostgreSQL so I would be very grateful if I could get help with this. I have spent about twenty minutes trying to find answers with no luck so far. Thanks in advance for whatever help you can offer!
Post Reply