SQL문은
<span> $this</span><span>-></span><span>db</span><span>-></span><span>select</span><span>(</span><span>'*'</span><span>)-></span><span>from</span><span>(</span><span>'mytable'</span><span>)</span><span>; </span>
<span> $count </span><span>= </span><span>$this</span><span>-></span><span>db</span><span>-></span><span>count_all_results</span><span>() ;</span>
$config = array(<br> 'base_url' => '/financing/dayconsumption',<br> 'total_items' => $count,<br> 'current_page' => $page,<br> 'items_per_page' => $this->pagesize,<br> );<br> $this->pagination2->init($config);<br> $this->db->limit($this->pagesize, $this->pagination2->sql_offset);<br> $query = $this->db->get();
입니다. . . . . .
실행 후 보고된 오류:
데이터베이스 오류가 발생했습니다
오류 번호: 1096
사용된 테이블 없음
SELECT * LIMIT 20
줄 번호: 330
디버깅 후 문제를 발견했습니다. <span>$count </span><span>= </span><span>$this</span><span>-></span><span>db</span><span>-></span><span>count_all_results</span><span>() ;</span>
여기에서 count_all_results()의 소스 코드를 확인하세요.
/** * "Count All Results" query * * Generates a platform-specific query string that counts all records * returned by an Active Record query. * * @param string * @return string */ public function count_all_results($table = '') { if ($table != '') { $this->_track_aliases($table); $this->from($table); } $sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows')); $query = $this->query($sql); $this->_reset_select(); //注意这里 if ($query->num_rows() == 0) { return 0; } $row = $query->row(); return (int) $row->numrows; }
/** * Resets the active record values. Called by the get() function * * @return void */ protected function _reset_select() { $ar_reset_items = array( 'ar_select' => array(), 'ar_from' => array(), 'ar_join' => array(), 'ar_where' => array(), 'ar_like' => array(), 'ar_groupby' => array(), 'ar_having' => array(), 'ar_orderby' => array(), 'ar_wherein' => array(), 'ar_aliased_tables' => array(), 'ar_no_escape' => array(), 'ar_distinct' => FALSE, 'ar_limit' => FALSE, 'ar_offset' => FALSE, 'ar_order' => FALSE, ); $this->_reset_run($ar_reset_items); }
/** * Resets the active record values. Called by the get() function * * @param array An array of fields to reset * @return void */ protected function _reset_run($ar_reset_items) { foreach ($ar_reset_items as $item => $default_value) { if ( ! in_array($item, $this->ar_store_array)) { $this->$item = $default_value; } } }
$this->db->start_cache(); $this->db->select('*')->from('mytable'); $this->db->stop_cache(); ...... $query = $this->db->get(); $items = $query->result(); $this->db->flush_cache();
위 내용은 관련 내용을 포함하여 codeigniter의 count_all_results() 문제를 소개하고 있으며, PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.