简体   繁体   English

使用Codeigniter从sqlite数据库中获取数据时出错

[英]error when fetching data from sqlite db using Codeigniter

I connected to sqlite db and tried to fetch data from a table . 我连接到sqlite db,并尝试从表中获取数据。

but its showing some error , 但是它显示了一些错误,

Fatal error: Call to a member function lastErrorCode() on a non-object in D:\\xampp\\htdocs\\e-hadith\\system\\database\\drivers\\sqlite3\\sqlite3_driver.php on line 300 A PHP Error was encountered 致命错误:在第300行上的D:\\ xampp \\ htdocs \\ e-hadith \\ system \\ database \\ drivers \\ sqlite3 \\ sqlite3_driver.php上的非对象上调用成员函数lastErrorCode()

Severity: Error 严重性:错误

Message: Call to a member function lastErrorCode() on a non-object 消息:在非对象上调用成员函数lastErrorCode()

Filename: sqlite3/sqlite3_driver.php 文件名:sqlite3 / sqlite3_driver.php

Line Number: 300 行号:300

Backtrace: 回溯:

below is my code 下面是我的代码

{
         $this->db->select("*");
         $q=$this->db->get("chapter");
         $r=$q->result();
         echo "<pre>";print_r($r);exit;


        $this->load->view('welcome_message');
    }
$db['default'] = array(
    'dsn'   => '',
    'hostname' => '',
    'username' => '',
    'password' => '',
    'database' => 'sqlite:'.APPPATH.'/Database/data.db',
    'dbdriver' => 'sqlite3',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => FALSE,
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

Can any one suggest me ? 有人可以建议我吗?

在此处输入图片说明

It looks there is some error in database configuration. 看起来数据库配置中有一些错误。

Possible issues 可能的问题

  1. Database Configuration Issue. 数据库配置问题。

'database' => 'sqlite:'.APPPATH.'/Database/data.db' , this is wrong. 'database' => 'sqlite:'.APPPATH.'/Database/data.db' ,这是错误的。

In CodeIgniter APPPATH refers to the application directory. 在CodeIgniter中, APPPATH是指application目录。

As per your screenshot your sqlite database is outside of the application directory. 根据您的屏幕截图,您的sqlite数据库位于application目录之外。

  1. Move the data.db file inside application/database . data.db文件移动到application/database
  2. Update the config 'database' => APPPATH.'/database/data.db' 更新配置'database' => APPPATH.'/database/data.db'
  3. Edit application/config/autoload.php and load database library. 编辑application/config/autoload.php并加载数据库库。

Hope this will resolve your issue. 希望这能解决您的问题。

First thing try to check your php.ini and uncomment this 首先尝试检查您的php.ini并取消注释

extension=php_pdo_sqlite.dll
extension=php_sqlite3.dll

and try this 并尝试这个

// in the dsn put sqlite:your/path/to/Database
$db['default'] = array(
    'dsn'   => 'sqlite:application/Database/data.db',
    'hostname' => 'localhost',
    'username' => '',
    'password' => '',
    'database' => '',
    'dbdriver' => 'pdo',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM