2016-06-13 185 views
0

通過引用下面的鏈接,我試圖用PHP連接sqlite數據庫。使用PHP連接到SQLite數據庫

How do I connect to an SQLite database with PHP?

<?php 
$dir = 'sqlite:/var/www/html/shijin/brandz_db'; 
$dbh = new PDO($dir) or die("cannot open the database"); 

但我收到以下錯誤,

Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in /var/www/html/shijin/sqlite.php:3 Stack trace: #0 /var/www/html/shijin/sqlite.php(3): PDO->__construct('sqlite:/var/www...') #1 {main} thrown in /var/www/html/shijin/sqlite.php on line 3

回答

0

你需要安裝PDO sqlite的驅動程序。嘗試

sudo pecl install pdo 
sudo pecl install pdo_sqlite 
+0

我使用Ubuntu,收到錯誤須藤:PECL:找不到 – Shin

+0

命令那我想'命令和apt-get安裝PHP5-sqlite3'應該做的:P – techouse

+0

@techouse我都試過了,但找不到包php5-sqlite3 – Shin