dongtuo1482 2014-10-21 23:54
浏览 97

PDO将数据库类型更改为SQLITE会引发错误

I have this database class, when I' am using Database Type as "mysql" everything works fine but changing from "mysql" to "sqlite" throws error on the page.

Here is the error message

Fatal error: Uncaught exception 'Exception' with message 'SQLSTATE[HY000]: General error: 1 no such table: users' in E:\xampp\htdocs\projects\test\pdo\database.php:33 Stack trace: #0 E:\xampp\htdocs\projects\test\pdo\index.php(3): db->select('SELECT * FROM u...') #1 {main} thrown in E:\xampp\htdocs\projects\test\pdo\database.php on line 33

This is the complete Class Code.

class db{
    public $isConnected;
    protected $datab;

    /* Database Object */
    public function __construct($username, $password, $host, $dbname, $options=array()){
        $this->isConnected = true;
        try { 
            $this->datab = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options); 
            $this->datab->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
            $this->datab->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
        } 
        catch(PDOException $e) { 
            $this->isConnected = false;
            throw new Exception($e->getMessage());
        }
    }

    /* Disconnect from the database */
    public function disconnect(){
        $this->datab = null;
        $this->isConnected = false;
    }

    /* Select Query Against the Database */
    public function select($query, $params=array()){
            try{ 
                $stmt = $this->datab->prepare($query); 
                $stmt->execute($params);
                return $stmt->fetchAll();       
            }catch(PDOException $e){
                throw new Exception($e->getMessage());
            }       
    }

    /* Insert Query Against the Database */
    public function insert($query, $params){
            try{ 
                $stmt = $this->datab->prepare($query); 
                $stmt->execute($params);
            }catch(PDOException $e){
                throw new Exception($e->getMessage());
            }           
    }

    /* Update Query Against the Database */
    public function update($query, $params){
            return $this->insert($query, $params);
    }

    /* Delete Query Against the Database */
    public function delete($query, $params){
            return $this->insert($query, $params);
    }
}
$db = new db("root", "", "localhost", "test", array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
  • 写回答

1条回答 默认 最新

  • douban5644 2014-10-22 12:08
    关注

    I was able to solve this issue by commenting out the pdo sqlite extensions on XAMPP.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog