Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Please can someone help me with this I cant find very much information on this problem.

I am connecting fine to PostgreSql database but when I look through the array and display nothing is being displayed, however the exact amount of rows are being displayed s oi know the connection/query are the right syntax, must be the variables syntax but ive tried everything I can find to make it work, any ideas?

<?php
pg_connect("host=******** port=**** dbname=****** user=***** password=********") or die("Couldn't Connect"); // Connect to the Database
$query = "SELECT * FROM phones";
$query = pg_query($query);
while($row = pg_fetch_array($query))
{

echo "Model: ".$row['Model']."<br />";
echo "OS: ".$row['OS']."<br />";
echo "Description: ".$row['Description']."<br /><br />";
}
?>

Thank you in advance for any help

share|improve this question
    
Try to dump the whole row first - most probably the result set doesn't have indices named 'Model', 'OS', etc. In that vein - using select * from is a bad practice. –  Milen A. Radev Nov 18 '13 at 23:44
    
Turns out it was the array indexes they were all lowercase, It worked on my local SQL server didn't even think to change them!! –  user2960322 Nov 18 '13 at 23:48

2 Answers 2

Try to use pg_last_error();

<?php
  $dbconn = pg_connect("dbname=publisher") or die("Could not connect");

  // Query that fails
  $res = pg_query($dbconn, "select * from doesnotexist");

  echo pg_last_error($dbconn);
?>

http://us2.php.net/pg_last_error

share|improve this answer

Try pg_fetch_assoc instead of pg_fetch_array, it might work. It works for MySQL.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.