PostgreSQL - Use PHP to Output Data in JSON Format
<?php
$connection=pg_connect("host=db_host.org port=5432 dbname=database_name user=your_username password=your_password");
$result = pg_query('SELECT * FROM some_table');
$rows = array();
while($r = pg_fetch_assoc($result)) {
$rows[] = $r;
}
echo json_encode(array_values(pg_fetch_all($result)));
?>
Comments