SQL語句是這樣的:
<span> $this</span><span>-></span><span>db</span><span>-></span><span>select</span> <span>(</span> <span>'我的桌子'</span><span>)</span><span>; </span><span></span><span></span><span> $count </span><span>= </span>
_這個
() ;<span></span><span> </span><span> $config = array(</span> 'base_url' => '/融資/每日消耗',<span> 'total_items = $page 'items_per_page' => $this->pagesize,</span> ); <span> $這個->pagination2->init($config);</span> $this->db->limit($this->pagesize, $ >get();<span></span><span> 。 。 。 。 。 。 </span><span>運行後報錯:</span>
發生資料庫錯誤
錯誤號碼:1096<br>沒有使用表<br><br>SELECT * LIMIT 20 <br> = <br><br>$this<br><br>->
/** * "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; }
其實到這裡,看註解就能猜到了,活動記錄被重置了。為了確認一下,繼續追蹤_reset_run(),就在_reset_select()上面:
/** * 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; } } }
<span>
</span>
以上就介紹了codeigniter中count_all_results()問題,包含了面向的內容,希望對PHP教學有興趣的朋友有幫助。 <span>
</span>
<span></span>