PHP isn't working with SQLite - php

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

Extension in Php.ini file should be:
extension=pdo_sqlite.so
extension=sqlite.so

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.

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.

Related

Function utf8_encode undefined

I have Ubuntu 16.04 installed, which comes with PHP 7 by default; but I ended up installing PHP 5.6 as well, and I have apache using 5.6.
When I went to run a project of mine, it told me the following:
PHP Fatal error: Call to undefined function utf8_encode()
I read through a bunch of posts where others have had this issue, and tried installing different extensions; but nothing has helped.
My understanding, was that that function would be packed with PHP (4,5,7) by default.
Any ideas?
* Update *
I did try the following, and it came back false.
var_dump(is_callable('utf8_encode'));
Here are the installed mods/extensions:
[PHP Modules]
calendar
Core
ctype
date
dom
ereg
exif
fileinfo
filter
ftp
gettext
hash
iconv
json
libxml
mbstring
mhash
mysql
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
Phar
posix
readline
Reflection
session
shmop
SimpleXML
sockets
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlrpc
xmlwriter
xsl
Zend OPcache
zlib
[Zend Modules]
Zend OPcache
on ubuntu :
sudo apt-get install php5.6-xml
sudo service apache2 restart
The following fixed it:
sudo a2enmod xml2enc
On FreeBSD try this command
pkg install php71-tokenizer-7.1.25 php71-zlib-7.1.25

Can't enable PDO MySQL extension in CentOS

I've added the following lines in php.ini
extension=pdo.so
extension=mysql.so
extension=pdo_mysql.so
But I'm still only getting sqlite support in phpinfo(); and a PHP app I'm trying to install shows "PHP PDO MySQL Module: Not Found".
however php -m gives the following list:
bcmath
calendar
Core
ctype
curl
date
dom
ereg
fileinfo
filter
ftp
gd
gettext
hash
iconv
intl
json
libxml
mbstring
mcrypt
mhash
mysql
mysqli
mysqlnd
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
xsl
zip
zlib
As it turns out the php-mysql package was an error state, I followed the instructions in another answer to resolve it
php-mysql version conflicts with Mysql server
if using windows just uncomment
extension_dir = "ext"
in php.ini
You have an CentOS(Red Hat(Linux)). You need to install the php_module like that:
sudo apt-get install php5-mysql
Then do an apache restart Like that:
sudo service apache2 restart

Unable to find Mongo class in Connection.php Symfony 2

This is quite an often occurring error, but since I tried a lot of stuff to fix it, I'm kind of getting out of the ideas.
I have a symfony 2 with mongo DB. I have set up my composer.json file to download doctrine-mongo and doctrine-mongo-bundle,
"doctrine/mongodb-odm": "1.0.*#beta",
"doctrine/mongodb-odm-bundle": "3.0.*#beta",
In order to download this 2 modules, I needed to have mongo extension installed into PHP. I have both of them, mongo and mongodb, installed via brew
brew install php56-mongo
brew install php56-mongodb
I believe I have mongo extensions allowed as well, since when I write
php -m
I get this results
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dba
dom
ereg
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
json
ldap
libxml
mbstring
mhash
mongo
mongodb
mysql
mysqli
mysqlnd
odbc
openssl
pcntl
pcre
PDO
pdo_mysql
PDO_ODBC
pdo_sqlite
Phar
posix
readline
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlrpc
xmlwriter
xsl
zip
zlib
and you can see mongo there.
Also php -i returns info that mongo is enabled.
But when I'm trying to hit app_dev.php file in my project, I still get this:
ClassNotFoundException in Connection.php line 284: Attempted to load
class "Mongo" from the global namespace. Did you forget a "use"
statement?
I'm using a Mac OS X and have chmod 777 on
app/logs
app/cache
web/
recursively.
Do you have any idea what can trigger this ?
Thank you.
PHP Cli and fpm/apache doesn't use the same configuration, which means your php -m may be not accurate.
What you can do is call http://php.net/manual/en/function.extension-loaded.php inside your php entry point file on your server and make sure its loaded. Restarting the processes can help as well.

Install PECL Intl on MAMP 2.2 with PHP 5.5.3

When i installed the framework Yii2 and i verified to launch requirements.php for check if PHP extensions have been loaded.
I installed icu4c using brew like :
brew install icu4c
I installed intl using PECL like :
/Applications/MAMP/bin/php/php5.5.3/bin/pecl install intl
Dir icu4c : /usr/local/Cellar/icu4c/52.1/
In PHPInfo, i have :
But in Yii2, i launched requirements.php and the extension intl is not always work.
Info : When i execute /Applications/MAMP/bin/php/php5.5.3/bin/php -m :
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dom
ereg
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
imap
json
ldap
libxml
mbstring
mcrypt
mysql
mysqli
openssl
pcre
PDO
pdo_mysql
pdo_pgsql
pdo_sqlite
pgsql
Phar
posix
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
xsl
yaz
Zend OPcache
zip
zlib
[Zend Modules]
Zend OPcache
And i see not where intl... Is this normal ? I wonder if the problem is rather to MAMP or PECL ?
Thanks.
EDIT :
Yii Framework fixed : https://github.com/yiisoft/yii2/issues/1230
It might be that PHP on apache uses a different php.ini files than PHP on CLI.
Find out for CLI by running
$ php --ini
The php.ini for apache can be seen in phpinfo().
If they are different, you need to add the extension loading directive to the CLI one, too.
Also make sure to restart apache after modifying the php.ini for mod_php.

how to install posix in php

POSIX does not appear when I run php -m cmd, however, I see it from the phpinfo() –enable-posix=shared on Linux with Plesk 9.
Basically, I can't use posix_*() functions as described at
http://www.php.net/manual/en/ref.posix.php
this shows doesn't exists:
if (function_exists('posix_getuid')) {
echo "posix_getuid available";
} else {
echo "posix_getuid not available"; // this prints in my server.
}
Could someone show me how to install it? Thank you.
[PHP Modules]
bz2
calendar
ctype
curl
date
dbase
dom
exif
fileinfo
filter
ftp
gd
geoip
gettext
gmp
hash
iconv
imap
ionCube Loader
json
libxml
mbstring
mcrypt
memcache
mhash
mysql
mysqli
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
readline
Reflection
session
shmop
SimpleXML
sockets
SPL
sqlite
standard
tokenizer
wddx
xml
xmlreader
xmlwriter
xsl
zip
zlib
I found the solution:
yum install php-process
This package enables php-posix.
While resolved, the original problem would seem to be that posix_getpwuid is not supported on Windows:
from: http://www.php.net/manual/en/function.posix-getpwuid.php
On Windows, posix_getpwuid() is not implemented
if you just want the username of the current user, you can use get_current_user().
To properly get the running user, test if function_exists('posix_getpwuid') and if not, assume you're running on Windows and call getenv('USERNAME').
In openSUSE use command zypper install php-posix for installing php-process for using php function posix_getuid

Categories