2015-05-03 100 views
0

我在debian7。爲什麼不能用PDO創建sqlite數據庫?

<?php 
echo "creating a databse \n"; 
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!"; 
?> 

我要創造我的SQLite數據庫voting.db的代碼,它跑翻過錯誤信息:

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} 

如何解決呢?

回答

0

您沒有PDO sqlite擴展,因爲它沒有安裝和/或因爲它未啓用。

在ArchLinux的:

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

在Debian你應該執行類似的步驟。我覺得下面的命令應該夠用了:

su -c 'apt-get install php5-sqlite'