how to enable sqlite3 for php?

2019-01-06 09:45发布

I am trying to install sqlite3 for PHP in Ubuntu.

I install apt-get php5-sqlite3 and edited php.ini to include sqlite3 extension.

When I run phpinfo(); I get

SQLITE3
SQLite3 support  enabled  
sqlite3 library version  3.4.2  

as shown above, sqlite3 is enabled. However, I get "Class SQLite3 not found" when I use

 new SQLite3("database");

标签: php sqlite3
10条回答
2楼-- · 2019-01-06 09:51

Only use:

sudo apt-get install php5-sqlite

and later

sudo service apache2 restart
查看更多
Luminary・发光体
3楼-- · 2019-01-06 09:52

The accepted answer is not complete without the remainder of instructions (paraphrased below) from the forum thread linked to:

cd /etc/php5/conf.d

cat > sqlite3.ini
# configuration for php SQLite3 module
extension=sqlite3.so
^D

sudo /etc/init.d/apache2 restart
查看更多
神经病院院长
4楼-- · 2019-01-06 09:52

The SQLite3 PDO driver is named SQLite, not SQLite3, so you can do:

new SQLite("database");

For a SQLite2 database:

new SQLite2("database");
查看更多
一夜七次
5楼-- · 2019-01-06 09:57

For PHP7, use

sudo apt-get install php7.0-sqlite3

and restart Apache

sudo apache2ctl restart
查看更多
ゆ 、 Hurt°
6楼-- · 2019-01-06 09:58
one thing I want to add , before you try to  install 
apt-get install php5-sqlite

or 

apt-get install php5-sqlite3 

search the given package is available or not :- 

 # apt-cache search 'php5'

After that you get :-

php5-rrd - rrd module for PHP 5

php5-sasl - Cyrus SASL extension for PHP 5

php5-snmp - SNMP module for php5

**php5-sqlite - SQLite module for php5**

php5-svn - PHP Bindings for the Subversion Revision control system

php5-sybase - Sybase / MS SQL Server module for php5


Here you get an idea about whether your version support or not ..
in my system I get **php5-sqlite - SQLite module for php5**
so I prefer to install 

**apt-get install php5-sqlite**
查看更多
Summer. ? 凉城
7楼-- · 2019-01-06 09:58

try this:

sudo apt-get --purge remove php5*
sudo apt-get install php5 php5-sqlite php5-mysql
sudo apt-get install php-pear php-apc php5-curl
sudo apt-get autoremove
sudo apt-get install php5-sqlite
sudo apt-get install libapache2-mod-fastcgi php5-fpm php5
查看更多
登录 后发表回答