Thread: FW: [GENERAL] "document contains no data"

FW: [GENERAL] "document contains no data"

From
"Jackson, Kevin J."
Date:
Michael,

I'm new to both PHP and PostgreSQL, and I had the same problem.

I fixed it by doing 2 things:

1) Requiring the database to be accessed by a username/passwd combination.
2) Connecting to the database with the username/passwd combination.

Here is my code:

    <?php
require ('project.inc.php3');

$db=pg_connect("host=$hostdb port=$dbport user=$pguser password=$pgpasswd
dbname=$dbname");

$query = "INSERT INTO project_request (submit_date, contact, department,
telephone, email, project_name, completion, project_descrip, project_goal)
VALUES
('$submit_date','$contact','$department','$telephone','$email','$project_nam
e','$completion','$project_descrip','$project_goal')";

$doit=pg_exec($db,$query);

pg_close($db);
?>

(I put the hostname, username, passwd and database name into the
'project.inc.php3' include file and adjusted the permissions, so no one can
see the actual values for those.)

Hope this helps!

kjj

-----Original Message-----
From: Michael [mailto:mstrait@w3workshop.com]
Sent: Wednesday, February 09, 2000 2:54 PM
To: pgsql-general@postgreSQL.org
Subject: [GENERAL] "document contains no data"


I have just installed PHP on my new Cobalt RaQ3i, which came with
PostgreSQL already installed.  Both PHP and PostgreSQL work
independently.  I have created several sample databases using psql.  My
test PHP scripts embedded in html work.  But when I try to use PHP to
access a PostgreSQL all I get is the "document contains no data"
message.  The PHP script I was trying to use is the one from the online
tutorial at http://cs.sau.edu/~cfisher/uw/018.html#06. I first created the
grocery database just as described in the tutorial, so I'm certain the
database is there and accessible through psql.  The script looks like this:

View Database Records
item vendorname quantity
<?PHP $conn = pg_Connect("", "", "", "", "grocery"); if (!$conn) { echo "An
error occurred.\n"; exit; } $result = pg_Exec($conn, "SELECT list.item,
vendors.vendorname, list.quantity FROM list, vendors WHERE list.vendorcode
= vendors.vendorcode ORDER BY list.item;"); if (!$result) { echo "An error
occurred.\n"; exit; } $num = pg_NumRows($result); $i = 0; while ($i < $num)
{ echo "
"; echo pg_Result($result, $i, "item"); echo ""; echo pg_Result($result,
$i, "vendorname"); echo ""; echo pg_Result($result, $i, "quantity"); echo "
"; $i++; } pg_FreeResult($result); pg_Close($conn); ?>


My PostgreSQL was installed to require user authorization, so I've tried
modifying the pg_connect line in the tutorial script like so:
$conn = pg_Connect("dbname=grocery user=mstrait password=michael");
but it didn't make a difference.

I need some help on where else to look for the problem.  If it matters, I'm
using PHP Version 3.0.14, PostgreSQL 6.5, and the web server is Apache
1.3.6.  The platform is a Cobalt RaQ3i running Linux 2.2.

Thanks.
Michael Strait
mstrait@w3workshop.com

************