0

I have this piece of code

<?

    $db = pg_connect("host=h port=p dbname=dbn user=usr password=pass");

    if ($db) {
        echo 'Connection attempt succeeded.' . '<br>' . '<br>';
    }
    else{   
        echo 'Connection attempt failed.' . '<br>' . '<br>';   
    }

    $query = "SELECT column1 FROM table";  
    $result = pg_query($db, $query);
    while ($row = pg_fetch_array($result)) echo $row. '<br>'. '<br>';

    echo pg_dbname($db). '<br>' ;
    echo pg_get_pid($db);
?>

The result should be three numeric values. When I run it, all I get are three strings "Array".

Connection attempt succeeded.

Array

Array

Array

dbname

pid

Can anyone help, please?

2
  • Try echo array(); You can't simply echo arrays. Commented Oct 4, 2013 at 11:35
  • use echo $row['column1'] and don't echo the array use instead print_r/var_dump functions Commented Mar 1, 2014 at 14:32

1 Answer 1

3

DO:

while ($row = pg_fetch_all($result)) echo $row['column1']. '<br>'. '<br>';

OR debug:

while ($row = pg_fetch_all($result)) var_dump($row) . '<br>'. '<br>';
Sign up to request clarification or add additional context in comments.

1 Comment

Super. I'm glad I can help :)

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.