PHP Postgresql Functions problem
Posted: Wed Jun 17, 2009 12:22 am
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:
If I use 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!
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);
}Code: Select all
"select * from pg_tables where schemaname='public';"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!