scott_pgsql_employee_2php.htm |
Using : for loops and pg_num_rows($result)
|
<?php // database access parameters // alter this as per your configuration $host = "localhost"; $user = "username"; $pass = "password"; $db = "pgsdemo1"; // open a connection to the database server $dbconn = pg_connect ("host=$host dbname=$db user=$user password=$pass"); if (!$dbconn) { die("Could not open connection to database server"); } echo "connection successful <br/>"; $result = pg_query($dbconn, "SELECT * FROM emp ORDER BY ename"); if ($result) { echo "The query executed successfully.<br />\n"; // show name of the fields $i = pg_num_fields($result); for ($j = 0; $j < $i; $j++) { //echo "column $j\n"; $fieldname = pg_field_name($result, $j); echo $fieldname." ||"; //echo "printed length: " . pg_field_prtlen($res, $fieldname) . " characters\n"; //echo "storage length: " . pg_field_size($res, $j) . " bytes\n"; // echo "field type: " . pg_field_type($res, $j) . " \n\n"; } echo"<br/><table border='1'>"; // for ($row = 0; $row < pg_num_rows($result); $row++) { $values = pg_fetch_row($result, $row); echo "<tr><td>"; echo implode(' ', $values) . "</td></tr>\n"; } echo "</table>"; } else { echo "The query failed with the following error:<br />\n"; echo pg_last_error($db_handle); } pg_close($dbconn); ?> |
![]() |