doucha4054 2015-05-03 02:27
浏览 47
已采纳

为什么不能用PDO创建sqlite db?

I am in debian7.

<?php
echo "creating a databse 
";
try {
    $dbh=new PDO('sqlite:voting.db');
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $dbh->exec('
    CREATE TABLE tally(
    QID varchar(32) NOT NULL,
    AID integer NOT NULL,
    votes integer NOT NULL,
    PRIMARY KEY(QID,AID)
    )');


} catch (Exception $e) {
    echo "error!!:$e";
    exit;

}
echo "db created successfully!";
?>

I want to create my sqlite db voting.db with the code,it ran accross error info:

creating a databse error!!:exception 'PDOException' with message 'could not find driver' in /var/www/sqlite1.php:4
Stack trace: #0 /var/www/sqlite1.php(4):
PDO->__construct('sqlite:voting.d...') #1 {main}

How to fix it?

  • 写回答

1条回答 默认 最新

  • dozan0001 2015-05-03 11:39
    关注

    You do not have the PDO sqlite extension, because it is not installed and/or because it is not enabled.

    On ArchLinux:

    su
    pacman -S php-sqlite
    sed -i 's|.*\(extension.*pdo.*sqlite.*\)|\1|' /etc/php/php.ini
    

    On Debian you should perform similar steps. I think the following command should be enough:

    su -c 'apt-get install php5-sqlite'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?