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 './locking.php'; try { $lock = new Locking(); if ($_POST && !empty($_POST['user_name'])) { $lockData = $lock->setLockStatus($_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 $lockData; } else { if ($_POST && empty($_POST['user_name'])) { $lockData = $lock->deleteLockStatus(); 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 $lockData; } else { $lockData = $lock->getLockStatus(); header("Content-Type: text/json"); header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1.
public static function isLock() { return file_exists(Locking::filePath()); }