1

Can someone please help explain why I am getting errors with Postgres query?

I have tried both variances of pg_fetch & pg_object in my query, but I continue to get a warning error:

Warning: pg_fetch_assoc() expects parameter 1 to be resource, boolean given in /opt/vhosts/body.php on line 45

Can someone help confirm that my query is correct, or if my assumption that I am getting a boolean return because I am not getting a response from the server for my specific table - therefore issue with server or db access...

I've checked DB connection, it is good and connected.

Here is my query:

<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);

    require_once ('.db.conf.php');
    $db = pg_connect($dbstr_RW);
    //$login = $_SERVER['PHP_AUTH_USER'];

 $result = pg_query($db, "select * from user");

?>

Here is my result array - logic is select all from user table and output city data within that table.

<?php

while($row = pg_fetch_assoc($result))
{
    echo $row['city']."<br>";
}

echo "</ul></div>";

?>
1
  • Error handling is missing in your code, that's why you don't see the real error. Commented Jan 8, 2015 at 8:46

1 Answer 1

1

You may not be connected to database because as per manual pg-connect return FALSE on failure. That's why pg_query($db, "select * from user"); gives error.

For pg_query it requires resource to database connection as first optional parameter.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.