Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Create pg.query.inc.php
- ===
- <?php
- $connectString = 'host=db_host.org port=5432 dbname=db_name user=your_username password=your_password';
- $link = pg_connect($connectString);
- if (!$link) {
- echo "error";
- } else {
- $result = pg_query($link, $sql);
- $rows = array();
- while($r = pg_fetch_assoc($result)) {
- $rows[] = $r;
- }
- print json_encode($rows);
- }
- ?>
- Create php file and pass in db connection
- ===
- <?php
- $sql = "SELECT id, first_name, last_name FROM person";
- include 'pg.query.inc.php';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment