问题
Okay, so this is my first server I'm setting up. I have a system running Ubuntu 11.10. I'm running Lighttpd and have PHP set up, but I want PHP and SQLite to work together. I installed them using:
sudo apt-get install lighttpd
sudo apt-get install php5-cgi
sudo apt-get install sqlite
sudo apt-get install php5-sqlite
PHP works fine, but any script with a sqlite command in it just returns a blank page. I turned on php error messages and ran this script:
<?php
echo sqlite_libversion();
echo "<br>";
echo phpversion();
?>
Which returns:
Fatal error: Call to undefined function sqlite_libversion()
What's gone wrong? :(
php -m
produces this:
[PHP Modules] bcmath bz2 calendar Core ctype date dba dom ereg exif fileinfo filter ftp gettext hash iconv json libxml mbstring mhash openssl pcntl pcre PDO pdo_sqlite Phar posix readline Reflection session shmop SimpleXML soap sockets SPL sqlite3 standard sysvmsg sysvsem sysvshm tokenizer wddx xml xmlreader xmlwriter zip zlib
回答1:
Extension in Php.ini file should be:
extension=pdo_sqlite.so
extension=sqlite.so
回答2:
According to http://packages.ubuntu.com/oneiric/all/php5-sqlite/filelist the php5-sqlite contains two extension modules
- pdo_sqlite.so -> http://docs.php.net/pdo
- sqlite3.so -> http://docs.php.net/sqlite3
so it looks like php5-sqlite
doesn't provide the module you're looking for.
If you don't have tons of legacy code I rather suggest you use PDO, esp. since the sqlite module is going to be moved from core php to pecl (nothing wrong with pecl though...):
Since PHP 5.0 this extension was bundled with PHP. Beginning with PHP 5.4, this extension is available only via PECL.
回答3:
Have you added the sqlite extensions in your php.ini?
It seems this guy had the same issue: http://forum.alwaysdata.com/viewtopic.php?id=1034
The solution in that thread was to add
extension=pdo_sqlite.so
extension=sqlite.so
To php.ini, preferably under the "Dynamic Extensions" sections, but they could go anywhere.
来源:https://stackoverflow.com/questions/9920995/php-isnt-working-with-sqlite