Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.
I have just installed an Ubuntu Server 16.04 with Nginx, and i have installed php in this way:
And for MySql i have installed percona, in this way:
but I can't understand why i can't use PDO in my php script, this is my code:
I get this error:
I have searched online and I have found that i have to uncomment this line in Windows in php.ini:
or this line on Linux:
I have checked my php.ini in:
and i have a
.dll file and not a
.so file, I can't also understand why I have a dll instead of a so. Anyway enabling that .dll file and restarting php nothing change. Anyone can help me?
Installing the mysql client/server packages doesn't effect PHP. PHP still needs the bindings to talk to your mysql server, specifically in your case the PDO mysql driver.
Pdoexception: Could Not Find Driver In
The package is probably going to be called
php7.0-pdo-mysql depending on which repositories are configured your Ubuntu package manager. If you're using PHP 7 on Ubuntu 16.04 it's more than likely going to be a meta package that includes
php7.0-mysql. Here's what I got from aptitude on 16.04 using the Ondrej PPA.
aptitude show php7.0-pdo-mysql
php7.0-pdo-mysql is the one we're interested in for loading the mysql driver for PDO in PHP. So make sure to search your package manager to find the correct package before you attempt installing, but there should be a similar package for your distro/repositories.
Once installed you'll need to restart php-fpm, something like
sudo service php7.0-fpm restart and then check your
phpinfo() to make sure the
pdo_mysql driver is now loaded.
You shouldn't need to edit your php.ini manually when installing through your package manager. Also, adding the
extension=pdo_mysql.so line to your php.ini has no effect if the extension doesn't exist. And obviously, trying to load dll won't work on linux, those are Windows-only libraries.