|
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
|
|
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
|
|
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
|
|