Re: postgresql database access failure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi.

<?php
>                $db = pg_connect('dbname=webcuttings user=httpd');
>                $query = 'SELECT * FROM articles';
>                $value=pg_fetch_result($query);
>                echo 'all files' $value;
>        ?>

Maybe a password is set on your database for the user httpd?

You have to first call pg_query(), which actually performs the query,
storing the returned results into some internal buffer, in the
unprocessed form that they get returned from the database, and only
then call pg_fetch_result() to reformat and extract one row. The
manual says:

<?php
$db = pg_connect("dbname=users user=me") || die();
$res = pg_query($db, "SELECT 1 UNION ALL SELECT 2");
$val = pg_fetch_result($res, 1, 0);
echo "First field in the second row is: ", $val, "\n";
?>

What you do is calling pg_fetch_result() before any result is
available, since you didn't actually perform the query yet.

Here's the URL of the relevant manual page:
http://www.php.net/manual/en/function.pg-fetch-result.php

My personal recommendation, however, is to drop old-style procedural
drivers and switch to PDO - it's much more convenient to use, IMO. If
you use PDO, you don't need to study the API of various different DB
drivers, and your code can easily switch from one database to another.

br,

flj

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux