Reputation: 639
I'm very new to php and Postgresql. When I was trying to retrieve data from my database, the query seems to always return a FALSE value. Here is my code:
$dbconn = pg_connect("host=localhost port=5432 dbname=mydb user=user password=user")
if(!$dbconn) {
echo "Not connected!";
}
$sql = 'SELECT * FROM "mytable"';
$query = pg_query($dbconn,$sql);
if(!$query) {
echo "There is an error!";
echo pg_last_error($dbconn);
}
Since the "not connect!" is not printed out, I'm quite sure my connection is correct. However, "There is an error!" is printed out, but pg_last_error() gives me an empty string.
Is there a reason why an empty string is passed back and is there other ways to retrieve the error message? Thanks a lot!
Upvotes: 1
Views: 3505
Reputation: 45902
Everything seems correct, so I would do the following:
e.g.
$dbconn = pg_connect("host=localhost port=5432 dbname=mydb user=user password=user");
var_dump($dbconn); // will it print "resource"?
echo pg_last_error($dbconn);
Upvotes: 3
Reputation: 452
can you try to change :
$sql = 'SELECT * FROM "mytable"';
By
$sql = "SELECT * FROM mytable";
It should fix your problem
Upvotes: 1