Esempio n. 1
0
 /**
  * Generated from @assert ("SELECT * FROM table WHERE id=:id AND lang IN (:lang, '')", array(':id' => 1, array(':lang' => 'th'))) [==] "SELECT * FROM table WHERE id=1 AND lang IN (th, '')".
  *
  * @covers Kotchasan\Text::replace
  */
 public function testReplace()
 {
     $this->assertEquals("SELECT * FROM table WHERE id=1 AND lang IN (th, '')", \Kotchasan\Text::replace("SELECT * FROM table WHERE id=:id AND lang IN (:lang, '')", array(':id' => 1, array(':lang' => 'th'))));
 }
 /**
  * อ่านข้อมูลจากแคช
  *
  * @param string $key
  * @param array $values (options)
  * @return mixed คืนค่าข้อมูลหรือ false ถ้าไม่มีแคช
  */
 public function get($sql, $values)
 {
     $this->item = $this->db_cache->getItem(Text::replace($sql, $values));
     return $this->item->isHit() ? $this->item->get() : false;
 }
Esempio n. 3
0
 /**
  * กำหนดคีย์ของแคชจาก query
  * 
  * @param string $sql
  * @param array $values
  * @return Item
  */
 public function init($sql, $values)
 {
     return $this->db_cache->getItem(Text::replace($sql, $values));
 }
Esempio n. 4
0
 /**
  * ฟังก์ชั่นบันทึกการ query sql
  *
  * @param string $type
  * @param string $sql
  * @param array $values (options)
  */
 protected function log($type, $sql, $values = array())
 {
     if (DB_LOG == true) {
         $datas = array('<b>' . $type . ' :</b> ' . Text::replace($sql, $values));
         foreach (debug_backtrace() as $a => $item) {
             if (isset($item['file']) && isset($item['line'])) {
                 if ($item['function'] == 'all' || $item['function'] == 'first' || $item['function'] == 'count' || $item['function'] == 'save' || $item['function'] == 'find' || $item['function'] == 'execute') {
                     $datas[] = '<br>[' . $a . '] <b>' . $item['function'] . '</b> in <b>' . $item['file'] . '</b> line <b>' . $item['line'] . '</b>';
                     break;
                 }
             }
         }
         // บันทึก log
         Logger::create()->info(implode('', $datas));
     }
 }