示例#1
0
 /**
  * Retrieve an entire SQL result set from the database (i.e., many rows)
  *
  * Executes a SQL query and returns the entire SQL result.
  *
  * @since 0.1
  *
  * @param string $query SQL query.
  * @return mixed Database query results
  */
 public function getResults($query = NULL)
 {
     if ($query) {
         $this->result = $this->mysqli->query($query);
     } else {
         return null;
     }
     return $this->result;
 }
示例#2
0
 /**
  * Internal method to show all cached data (used for debugging)
  * @access private
  * @return boolean
  */
 private function show_all()
 {
     $query = "SELECT expires, body FROM cache";
     if ($result = $this->db->query($query)) {
         if ($result->size() > 0) {
             $results = $result->fetchAll();
             echo '<pre>';
             print_r($results);
             echo '</pre>';
         } else {
             return false;
         }
     } else {
         // TODO: Handle error
         return false;
     }
 }
 /**
  * Perform a MySQL database query, using current database connection.
  *
  * More information can be found on the codex page.
  *
  * @since 0.1
  *
  * @param string $query Database query
  * @return int|false Number of rows affected/selected or false on error
  */
 public function query($query)
 {
     $return_val = 0;
     $this->flush_var();
     $this->last_query = $query;
     $this->result = $this->mysqli->query($query);
     // If there is an error then take note of it..
     if ($this->mysqli->errno) {
         $this->json_response->makeError($this->exception, $this->mysqli->error);
         $this->print_error();
         return false;
     }
     if (preg_match('/^\\s*(create|alter|truncate|drop) /i', $query)) {
         $return_val = $this->result;
     } elseif (preg_match('/^\\s*(insert|delete|update|replace) /i', $query)) {
         $this->affected_rows = $this->mysqli->affected_rows;
         // Take note of the insert_id
         if (preg_match('/^\\s*(insert|replace) /i', $query)) {
             $this->insert_id = $this->mysqli->insert_id;
         }
         // Return number of rows affected
         $return_val = $this->rows_affected;
     } else {
         $i = 0;
         while ($i < @$this->result->field_count) {
             $this->column_info[$i] = @$this->result->fetch_field();
             $i++;
         }
         $num_rows = 0;
         while ($row = @$this->result->fetch_object()) {
             $this->last_result[$num_rows] = $row;
             $num_rows++;
         }
         $this->result->free();
         // Log number of rows the query returned
         // and return number of rows selected
         $this->num_rows = $num_rows;
         $return_val = $num_rows;
     }
     return $return_val;
 }
示例#4
0
文件: dao.php 项目: actcms/nowphp
 /**
  * 根据条件返回数据库中的查询结果
  * @author 欧远宁
  * @param array $filter 筛选条件
  * @param array $page   分页条件    $page=array('cur'=>1,'size'=>20,'ttl'='n')
  * @param string $order 排序条件
  * @return array
  */
 private function query($filter, $page = null, $order = null)
 {
     $sql = 'SELECT ' . $this->key . ' FROM `' . $this->tbl . '` WHERE 1=1';
     foreach ($filter as $k => $v) {
         $sql .= ' AND ' . $k . ' = :' . $k;
     }
     $filter = $this->pre_para($filter);
     //根据需要返回分页信息
     if (is_array($page) && key_exists('ttl', $page) && $page['ttl'] == 'y') {
         $psql = str_replace('SELECT ' . $this->key, 'SELECT count(' . $this->key . ') AS ttl', $sql);
         $plist = $this->db->query($psql, $filter);
         $result['ttl'] = $plist[0]['ttl'];
     } else {
         $result['ttl'] = null;
     }
     if (!is_null($order) && $order !== '') {
         $sql .= ' ORDER BY ' . $order;
     }
     $result['list'] = $this->db->query($sql, $filter, $page);
     return $result;
 }