예제 #1
0
define('DATABASE_PASS', _PWD_);
define('DATABASE_HOST', _HOST_);
require_once 'class.DBPDO.php';
use DBPDO;
class CoreModel
{
    private $data;
    function __construct()
    {
        $this->DB = new DBPDO();
    }
    public function get()
    {
        $sql = "SELECT * FROM assistance ";
        $items = $this->DB->fetchAll($sql, null);
        $this->data = $items;
        return $this;
    }
    public function toJSON()
    {
        $results = array();
        foreach ($this->data as $key => $page) {
            array_push($results, (object) $page);
        }
        header('Content-Type: application/json', true);
        echo json_encode($results);
    }
}
$coreModel = new CoreModel();
$coreModel->get()->toJSON();