protected static function getConnction() { if (!self::$conn) { try { // Ideally this would be in a noSql flat table. self::$conn = new PDO('mysql:host=localhost;dbname=mydatabase', 'root', ''); } catch (PDOException $e) { //Need to raise exception and let error controller handle it. echo json_encode(array("Error" => $e->getMessage())); die; } } return self::$conn; }
<?php require_once './lightboard.php'; try { $board = new Lightboard(); if ($_POST) { $boardData = $board->postAction($_POST); header("Content-Type: text/json"); header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1. header("Pragma: no-cache"); // HTTP 1.0. header("Expires: 0"); // Proxies. echo $boardData; } else { $boardData = $board->indexAction(); header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1. header("Pragma: no-cache"); // HTTP 1.0. header("Expires: 0"); // Proxies. header("Content-Type: text/json"); echo $boardData; } } catch (Exception $exec) { header("HTTP/1.1 500 Server Error"); header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1. header("Pragma: no-cache");