1

I am trying to connect to and select data from an PostgreSQL server. I am able to connect to the server but my select query appears to be running an error. Any suggestions?

<?php

$conn = "host=#### port=5432 dbname=consolidated user=#### password=####";

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully";

$dbconn = pg_connect($conn);

$result = pg_query($dbconn, "SELECT id FROM retailer_retailer;");
if (!$result) {
  echo "An error occurred.\n";
  exit;
}

while ($row = pg_fetch_row($result)) {
  echo "ID: $row[0]";
  echo "<br />\n";
}

?>
2
  • The semi-colon is unnecessary, but try checking for pg_last_error when your query fails. Commented Jan 4, 2017 at 17:49
  • @aynber I tried echo pg_last_error($result); but nothing came up Commented Jan 4, 2017 at 17:52

1 Answer 1

1

you miss the schema name right here, I assume you have table in public schema and your query should like-

$result = pg_query($dbconn, "SELECT id FROM public.retailer_retailer;");

If you have another schema then you can replace public with other schema name

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

3 Comments

let me know whether it works for you or not, if worked accept it as answer
@veshar_joshi I am trying to link to a public scheme but this still doesn't work
did you get any erroor

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.