Reputation: 291
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";
}
?>
Upvotes: 1
Views: 46
Reputation: 3579
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
Upvotes: 1