/** * To check a particular key exists in the dictionary. * * @param <object> $key */ public function ContainsKey($key) { $objectID = $key->getObjectID(); if (array_key_exists($objectID, $this->_entries)) { return TRUE; } return FALSE; }
/** * * @param type $from */ public function search() { //whitelisting to prevent sql injection if ($this->order != 'Asc' && $this->order != 'Desc') { $this->order = 'Desc'; } if (!in_array($this->sort, array_keys($this->sort_keys))) { $this->sort = "post_created"; } //$t1 = microtime(true); $base_qry = $this->build_query(); $qry = $this->setSelectors($base_qry, $this->getSelectors()); $obj = $this->db->prepare($qry); if (!empty($this->cats)) { $this->values = array_merge($this->values, array($this->cats)); } $values = $this->values; $obj->execute($this->values); $res = $obj->fetchAll(); if ($this->count_rows) { if ($this->isMySQL) { $cnt_qry = 'SELECT FOUND_ROWS();'; $cnt_obj = $this->db->prepare($cnt_qry); $cnt_obj->execute(); } else { $cnt_qry = $this->setSelectors($base_qry, 'COUNT(p.post_id)'); $cnt_obj = $this->db->prepare($cnt_qry); $cnt_obj->execute($values); } $rows = $cnt_obj->fetch(); $this->count = $rows[0]; } return $res; //echo microtime(true) - $t1; }
/** * *取结果$result中第一行记录 * * @param <object> $result :查询结果数据集 * @param <bool> $assoc :true 返回数组; false 返回stdClass对象;默认 false * @return 没有结果返回 false */ public static function fetchRow($result = null, $assoc = false) { if (empty($result)) { return false; } if ($assoc) { return $result->fetch_assoc(); } else { return $result->fetch_object(); } }