deeejay icon

PostgreSQL - Use PHP to Output Data in JSON Format

deeejay | PRO | 06/14/16 09:05:16 PM UTC | 0 ⭐ | 286 👁️ | Never ⏰ | []
PHP |

310 B

|

None

|

0 👍

/

0 👎

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