postgresql-demos/php/postgresql-demo.php

29 lines
639 B
PHP
Raw Normal View History

2018-12-21 16:03:06 -03:00
<?php
$conn = pg_connect('host=localhost port=5432 dbname=bdd user=bdd password=bdd');
if (!$conn) {
echo 'Database connection failed!';
exit(1);
}
$result = pg_query($conn, 'SELECT * FROM turista');
if (!$result) {
echo 'SELECT failed: '.pg_last_error($conn);
exit(1);
}
echo '<table border=1><tr>';
for ($i = 0; $i < pg_num_fields($result); $i++) {
echo '<td>'.pg_field_name($result, $i).'</td>';
}
echo '</tr>';
while ($row = pg_fetch_row($result)) {
echo '<tr>';
for ($i = 0; $i < pg_num_fields($result); $i++) {
echo '<td>'.$row[$i].'</td>';
}
echo '</tr>';
}
2018-12-22 19:50:23 -03:00
pg_free_result($result);
2018-12-21 16:03:06 -03:00
echo '</table>';
pg_close($conn);
?>