Example #1
0
 public function setDb($pdo)
 {
     if ($pdo) {
         $this->pdo = $pdo;
     } else {
         $this->pdo = SQLHandler::connect();
     }
 }
Example #2
0
 public function all()
 {
     $result = array();
     $total = 0;
     try {
         $isPage = $_REQUEST['offset'];
         $sql = "SELECT * FROM " . $_REQUEST['model'];
         if (isset($isPage)) {
             $_sql = "SELECT COUNT(*) AS total FROM " . $_REQUEST['model'];
             $_data = SQLHandler::executeSQL($this->conn, 'get', $_sql);
             $total = $_data[0]["total"];
             $offset = $_REQUEST['offset'];
             $size = $_REQUEST['size'];
             $sql = $sql . " LIMIT " . $offset . "," . $size . ";";
         }
         $data = SQLHandler::executeSQL($this->conn, 'get', $sql);
         $result = array("sql" => $sql, "payload" => $data, "total" => $total);
     } catch (Exception $e) {
         $result = array("error" => $e->getMessage());
     }
     return $result;
 }
Example #3
0
 public function checkToken($token)
 {
     $result = false;
     try {
         $args = array("token" => md5($token . "bms"));
         $sql = "SELECT id FROM bms_user WHERE token=:token";
         $rows = SQLHandler::executeSQL($this->conn, 'post', $sql, $args);
         if (count($rows) > 0) {
             $result = true;
         }
     } catch (Exception $e) {
         throw $e;
     }
     return $result;
 }
Example #4
0
 public function read($id)
 {
     $result = array();
     try {
         $sql = "SELECT * FROM " . $_REQUEST['model'] . " WHERE id=" . $id;
         $res = SQLHandler::executeSQL($this->conn, 'get', $sql);
         $result = $res[0];
     } catch (PDOException $e) {
         $result = array("error" => $e->getMessage());
     }
     return $result;
 }