Example #1
0
 /**
  * ประมวลผลคำสั่ง SQL สำหรับสอบถามข้อมูล คืนค่าผลลัพท์เป็นแอเรย์ของข้อมูลที่ตรงตามเงื่อนไข.
  *
  * @param string $sql query string
  * @param array $values ถ้าระบุตัวแปรนี้จะเป็นการบังคับใช้คำสั่ง prepare แทน query
  * @param \Core\Database\Cache $cache  database cache class default null
  * @return array|boolean คืนค่าผลการทำงานเป็น record ของข้อมูลทั้งหมดที่ตรงตามเงื่อนไข หรือคืนค่า false หามีข้อผิดพลาด
  */
 protected function doCustomQuery($sql, $values = array(), $cache = null)
 {
     if ($cache && $cache->action > 0) {
         $result = $cache->get($sql, $values);
     } else {
         $result = false;
     }
     if (!$result) {
         try {
             if (empty($values)) {
                 $this->result_id = $this->connection->query($sql);
             } else {
                 $this->result_id = $this->connection->prepare($sql);
                 $this->result_id->execute($values);
             }
             self::$query_count++;
             $result = $this->result_id->fetchAll(PDO::FETCH_ASSOC);
             if ($cache && $cache->action == 1) {
                 $cache->save($result);
             }
         } catch (PDOException $e) {
             $this->error_message = $e->getMessage();
             $result = false;
         }
         $this->used_cache = false;
     } else {
         $this->used_cache = true;
     }
     $this->log($this->used_cache ? 'Cached' : 'Database', $sql, $values);
     return $result;
 }
Example #2
0
 /**
  * เปิดการใช้งานแคช
  * จะมีการตรวจสอบจากแคชก่อนการสอบถามข้อมูล
  *
  * @param boolean $auto_save (options) true (default) บันทึกผลลัพท์อัตโนมัติ, false ต้องบันทึกแคชเอง
  */
 private function cacheOn($auto_save = true)
 {
     $this->cache->cacheOn($auto_save);
     return $this;
 }