postgresql-demos/php/postgresql-demo.php
2018-12-21 16:03:06 -03:00

28 lines
614 B
PHP

<?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>';
}
echo '</table>';
pg_close($conn);
?>