The FreeBSD Diary

The FreeBSD Diary (TM)

Providing practical examples since 1998

If you buy from Amazon USA, please support us by using this link.
[ HOME | TOPICS | INDEX | WEB RESOURCES | BOOKS | CONTRIBUTE | SEARCH | FEEDBACK | FAQ | FORUMS ]
 New Topic  |  Go to Top  |  Go to Topic  |  Search  |  Log In   Newer Topic  |  Older Topic 
 Update
Author: Gerard Samuel 
Date:   20-06-02 07:44

Some php code with respect to postgresql has been changed lately, so here is an updated example....
I currently using php 4.2.1

<?php

$conn = pg_connect("dbname=test user=myuser");

if ($conn)
{
$result = pg_exec ($conn, 'select * from test');
if ($result)
{
echo pg_numrows($result) . ' rows to fetch' . "\n";
echo '<table border="1" width="50%">' . "\n";

while ($myrow = pg_fetch_array ($result))
{
echo '<tr><td>' . $myrow['id'] . '</td><td>' . $myrow['name'] . '</td></tr>' . "\n";
}

echo '</table>' . "\n";
}
else
{
echo 'read from test failed';
}
}
else
{
echo 'no connection';
}

?>

Reply To This Message
 
 Re: Update
Author: Gerard Samuel 
Date:   20-06-02 07:56

That didn't come out too pretty. Trying once more....

<pre>

<?php

$conn = pg_connect("dbname=test user=www");

if ($conn)
{
$result = pg_exec ($conn, "select * from test");
if ($result)
{
echo pg_numrows($result) . " rows to fetch\n";
echo "<br><br>\n";

while ($myrow = pg_fetch_array ($result))
{
echo " $myrow[id] $myrow[name] \n";
}
}
else
{
echo "read from test failed";<br> \n";
}
}
else
{
echo "no connection";
}

?>

</pre>

Reply To This Message
 
 Re: Update
Author: Dan Langille 
Date:   20-06-02 14:38

Thanks

Gerard Samuel wrote:
>
> while ($myrow = pg_fetch_array ($result))

Are you sure about that one? Looking at <A HREF="http://www.php.net/manual/en/function.pg-fetch-array.php">http://www.php.net/manual/en/function.pg-fetch-array.php</A> I see:

array pg_fetch_array ( resource result, int row [, int result_type])

You need to supply a row number.

Apart from that, what was the change you were trying to highlight?

Reply To This Message
 Forum List  |  Threaded View   Newer Topic  |  Older Topic 


 Forum List  |  Need a Login? Register Here 
 User Login
 User Name:
 Password:
 Remember my login:
   
 Forgot Your Password?
Enter your email address or user name below and a new password will be sent to the email address associated with your profile.
How to get the most out of the forum

phorum.org