脚本宝典收集整理的这篇文章主要介绍了php – CodeIgniter Sqlite无法正常工作,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
$this->db->select('post'); $query = $this->db->get('posts'); return $query->result_array();
我收到以下错误:
Fatal error: Call to a member function rowcount() on a non-object in /codeigniter/system/database/drivers/pdo/pdo_result.PHP on line 42
A Database Error Occurred Error Number: HY000 no such column: posst SELECT posst From posts Filename: /codeigniter/models/post.PHP Line Number: 8
这让我相信数据库实际上正在运行,但是我有些遗漏.
我试过重新创建数据库.它实际上有1个表,1列,但我无法获得任何数据.我也尝试使用不同的“管理”程序创建它,但无济于事.我确定它是一个sqlite 3 db,根据PHPinfo网络服务器支持它.
有人在我犯错的地方有线索吗?
<?PHP class Post extends CI_Model{ function get_posts(){ $this->db->select('posst'); $query = $this->db->get('posts'); return $query->result_array(); } }
我的控制器在controller / posts.PHP中:
<?PHP class Posts extends CI_Controller{ function index(){ $this->load->model('post'); $data['posts']=$this->post->get_posts(); echo"<PRe>"; print_r($data['posts']); echo"</pre>"; } }
$active_group = 'default'; $active_record = TRUE; $db['default']['hostname'] = 'sqlite:/home/******/******/www/wtP3/codeigniter/db/wtp35.sqlite'; $db['default']['username'] = ''; $db['default']['password'] = ''; $db['default']['database'] = ''; $db['default']['dbdriver'] = 'pdo'; $db['default']['dbprefix'] = ''; $db['default']['pconnect'] = TRUE; $db['default']['db_debug'] = TRUE; $db['default']['cache_on'] = FALSE; $db['default']['cachedir'] = ''; $db['default']['char_set'] = 'utf8'; $db['default']['dbcollat'] = 'utf8_general_ci'; $db['default']['swap_pre'] = ''; $db['default']['autoinit'] = TRUE; $db['default']['stricton'] = FALSE;
empty($this->database) OR $this->hostname .= ';dbname='.$this->database; $this->trans_enabled = FALSE; $this->_random_keyword = ' RND('.time().')'; // database sPEcific random keyword }
至
if(strpos($this->database,'sqlite') !== FALSE) { $this->hostname = $this->database; $this->_random_keyword = ' RANDOM()'; } else { $this->hostname .= ";dbname=".$this->database; $this->_random_keyword = ' RND('.time().')'; // database specific random keyword } $this->trans_enabled = FALSE; }
function _execute($sql) { $sql = $this->_prep_query($sql); $result_id = $this->conn_id->query($sql); if (is_object($result_id)) { $this->affect_rows = $result_id->rowCount(); } else { $this->affect_rows = 0; } return $result_id; }
public $num_rows;
至
VAR $pdo_results = ''; var $pdo_index = 0;
在36号线上取代整个功能
public function num_rows() { if (is_int($this->num_rows)) { return $this->num_rows; } elseif (($this->num_rows = $this->result_id->rowCount()) > 0) { return $this->num_rows; } $this->num_rows = count($this->result_id->fetchAll()); $this->result_id->execute(); return $this->num_rows; }
有:
function num_rows() { if ( ! $this->pdo_results ) { $this->pdo_results = $this->result_id->fetchAll(PDO::FETCH_ASSOC); } return sizeof($this->pdo_results);
然后在第60行改变
function num_fields() { return $this->result_id->columnCount(); }
至:
function num_fields() { if ( is_array($this->pdo_results) ) { return sizeof($this->pdo_results[$this->pdo_index]); } else { return $this->result_id->columnCount(); } }
然后在第94行更改:
function field_data() { $data = array(); try { for($i = 0; $i < $this->num_fields(); $i++) { $data[] = $this->result_id->getColumnMeta($i); } return $data; } catch (Exception $e) { if ($this->db->db_debug) { return $this->db->display_error('db_unsuported_feature'); } return FALSE; } }
至:
function field_data() { if ($this->db->db_debug) { return $this->db->display_error('db_unsuported_feature'); } return FALSE; }
然后第146行改变:
return FALSE;
至
$this->pdo_index = $n;
然后在第159行改变
function _fetch_assoc() { return $this->result_id->fetch(PDO::FETCH_ASSOC); }
至
function _fetch_assoc() { if ( is_array($this->pdo_results) ) { $i = $this->pdo_index; $this->pdo_index++; if ( isset($this->pdo_results[$i])) return $this->pdo_results[$i]; return null; } return $this->result_id->fetch(PDO::FETCH_ASSOC); }
最后在第174行改变:
function _fetch_object() { return $this->result_id->fetchObject();
至
function _fetch_object() { if ( is_array($this->pdo_results) ) { $i = $this->pdo_index; $this->pdo_index++; if ( isset($this->pdo_results[$i])) { $back = new stdClass(); foreach ( $this->pdo_results[$i] as $key => $val ) { $back->$key = $val; } return $back; } return null; } return $this->result_id->fetch(PDO::FETCH_OBJ); }
这对我有用.再一次,不是我的工作,信任是S.Stüvel,J.Bransen和S. Timmer.相当长的答案,但我希望这会有所帮助.
以上是脚本宝典为你收集整理的php – CodeIgniter Sqlite无法正常工作全部内容,希望文章能够帮你解决php – CodeIgniter Sqlite无法正常工作所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。