dir connection in separate file

master
Matt Huntington 8 years ago
parent 99ffdc74e7
commit 61dba44d59

@ -1,6 +1,6 @@
<?php <?php
header('Content-Type: application/json'); header('Content-Type: application/json');
include __DIR__ . '/../models/person.php'; include_once __DIR__ . '/../models/person.php';
if($_REQUEST['action'] === 'index'){ if($_REQUEST['action'] === 'index'){
echo json_encode(People::find()); echo json_encode(People::find());

@ -0,0 +1,3 @@
<?php
$dbconn = pg_connect("host=localhost dbname=phpapi");
?>

@ -1,4 +1,6 @@
<? <?
include_once __DIR__ . '/../database/db.php';
class Person { class Person {
public $name; public $name;
public $age; public $age;
@ -7,9 +9,9 @@ class Person {
$this->age = $age; $this->age = $age;
} }
} }
class People { class People {
static function find(){ static function find(){
$dbconn = pg_connect("host=localhost dbname=phpapi");
$result = pg_query('SELECT * FROM people'); $result = pg_query('SELECT * FROM people');
$people = array(); $people = array();
while($data = pg_fetch_object($result)){ while($data = pg_fetch_object($result)){

Loading…
Cancel
Save