Ошибка could not find driver

I have just installed Debian Lenny with Apache, MySQL, and PHP and I am receiving a PDOException could not find driver.

This is the specific line of code it is referring to:

$dbh = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASS)

DB_HOST, DB_NAME, DB_USER, and DB_PASS are constants that I have defined. It works fine on the production server (and on my previous Ubuntu Server setup).

Is this something to do with my PHP installation?

Searching the internet has not helped, all I get is experts-exchange and examples, but no solutions.

ghbarratt's user avatar

ghbarratt

11.5k4 gold badges41 silver badges41 bronze badges

asked May 17, 2010 at 20:57

Mike Moore's user avatar

8

You need to have a module called pdo_mysql. Looking for following in phpinfo(),

pdo_mysql

PDO Driver for MySQL, client library version => 5.1.44

answered May 17, 2010 at 21:33

ZZ Coder's user avatar

ZZ CoderZZ Coder

74.5k29 gold badges137 silver badges169 bronze badges

10

The dsn in your code reveals you are trying to connect with the mysql driver. Your error message indicates that this driver is unavailable.

Check that you have the mysql extension installed on your server.

In Ubuntu/Debian you check for the package with:

dpkg --get-selections | grep php | grep mysql

Install the php5-mysql package if you do not have it.

In Ubuntu/Debian you can use:

  • PHP5: sudo apt-get install php5-mysql
  • PHP7: sudo apt-get install php7.0-mysql

Lastly, to get it working, you will need to restart your web-server:

  • Apache: sudo /etc/init.d/apache2 restart
  • Nginx: sudo /etc/init.d/nginx restart

answered Nov 10, 2011 at 5:21

ghbarratt's user avatar

ghbarrattghbarratt

11.5k4 gold badges41 silver badges41 bronze badges

2

Update: newer versions should use php-sqlite3 package instead of php5-sqlite. So use this, if you are using a recent ubuntu version:

sudo apt-get install sqlite php-sqlite3

Original answer to question is here:

sudo apt-get install sqlite php5-sqlite
sudo /etc/init.d/apache2 restart

If your phpinfo() is not showing the pdo_sqlite line (in my case, on my Ubuntu Server), you just need to run the lines above and then you’ll be good to go.

answered Aug 27, 2010 at 18:39

Sudipta Chatterjee's user avatar

8

For newer versions of Ubuntu that have PHP 7.0 you can get the php-mysql package:

sudo apt-get install php-mysql

Then restart your server:

sudo service apache2 restart

answered Aug 19, 2016 at 6:28

ThomasAFink's user avatar

ThomasAFinkThomasAFink

1,26714 silver badges25 bronze badges

1

I had the same issue. The solution depends on OS. In my case, i have debian, so to solve it:

  • Updated my php version from (php5 to php7)
  • Install php-mysql and php7.0-mysql

    apt-get install php-mysql
    apt-get install php7.0-mysql
    
  • I edited my php.ini locate at /etc/php/7.0/apache2/php.ini

    uncomment the line : extension=php_pdo_mysql.dll
    
  • Then restart apache:

    service apache2 restart
    

This solves my problem

Community's user avatar

answered Jun 5, 2017 at 1:26

onlyme's user avatar

onlymeonlyme

3,8062 gold badges23 silver badges17 bronze badges

1

On my Windows machine, I had to give the absolute path to the extension dir in my php.ini:

extension_dir = "c:\php5\ext"

fvrghl's user avatar

fvrghl

3,6325 gold badges28 silver badges36 bronze badges

answered Jun 10, 2013 at 22:41

berdzi's user avatar

berdziberdzi

2613 silver badges2 bronze badges

2

Check if the module is available with php -m | grep pdo_mysql.

If not, for PHP 7.2, you can install relevant package with sudo apt install php7.2-mysql.

Use similar command on other PHP versions and package managers.

answered Jul 4, 2019 at 5:30

Pratik's user avatar

PratikPratik

9591 gold badge14 silver badges20 bronze badges

On Ubuntu just execute

sudo apt-get install php5-mysql

answered Apr 16, 2013 at 13:22

Dmitry Sobolev's user avatar

2

sudo apt-get install php-mysql 

worked well on ubuntu and php 7

answered May 12, 2016 at 9:11

Moses Nandwa's user avatar

1

When adding these into your php.ini ensure the php_pdo.dll reference is first before the db drivers dlls otherwise this will also cause this error message too. Add them like this:

[PHP_PDO]
extension=php_pdo.dll
[PHP_PDO_MYSQL]
extension=php_pdo_mysql.dll

Luís Cruz's user avatar

Luís Cruz

14.8k16 gold badges68 silver badges100 bronze badges

answered Nov 17, 2014 at 23:33

Paul Foster's user avatar

1

for Windows 8.1/10 in :\\php.ini file you should uncomment line «extension=pdo_mysql»

answered Dec 19, 2017 at 16:18

Egor Doynikov's user avatar

Did you check your php.ini (check for the correct location with phpinfo()) if MySQL and the driver is installed correctly?

answered May 17, 2010 at 21:08

cem's user avatar

cemcem

3,3211 gold badge18 silver badges23 bronze badges

1

For PHP 5.5 on CentOS I fixed this by installing the php55-mysqlnd package.

sudo yum -y install php55w-mysqlnd # For Webtatic
sudo yum -y install php55u-mysqlnd # For Remi

For help installing, write a comment as it depends on the way PHP is installed on your system. Available repo’s are webtatic and remi.

answered Jul 23, 2014 at 9:22

SimonW's user avatar

SimonWSimonW

6,1854 gold badges33 silver badges39 bronze badges

I had the same problem during running tests with separate php.ini. I had to add these lines to my own php.ini file:

[PHP]
extension = mysqlnd.so
extension = pdo.so
extension = pdo_mysql.so

Notice: Exactly in this order

answered Jul 23, 2016 at 15:04

Facedown's user avatar

FacedownFacedown

1921 gold badge2 silver badges10 bronze badges

0

Incorrect installation of PHP was being called

I was experiencing the same problem. And I hope this would help someone who is having a similar issue as me.

Scenario

OS = Windows 10  
Platform = XAMPP  
PHP Version = 7 (Multiple Version seem to have been installed in the PC)  

I created phpinfo.php file in the public folder and run the phpinfo() to look for the location of my php.ini file.

PHP.ini Location = c:\xampp\php\php.ini

Problem
Calling c:\xampp\htdocs> php -v returned PHP 7.2.3 but phpinfo.php showed PHP 7.2.2.

Solution
Instead of calling

php artisan migrate:install   

which gave me this error, I used

c:\xampp\php\php artisan migrate:install

and it worked.

answered Sep 21, 2018 at 10:21

RealSollyM's user avatar

RealSollyMRealSollyM

1,5301 gold badge22 silver badges35 bronze badges

Check if extension_dir in php configuration file set correctly. Try to comment/uncomment some extensions and see if it’s reflected on phpinfo().
If it doesn’t then either php config file cannot be loaded (wrong location) extension_dir is commented or set to the wrong location.

answered Aug 18, 2012 at 14:02

hserge's user avatar

hsergehserge

9051 gold badge9 silver badges12 bronze badges

In my case my DSN string was incorrect, specifically it did not contain mysql://. I would have expected a different error message, perhaps something like ‘DSN string does not specify driver/protocol.’

Adding mysql:// to the beginning of the DSN string resolved the issue.

random_user_name's user avatar

answered Jun 21, 2012 at 16:38

gposton's user avatar

I spent the last day trying to figure out why I was getting the following error. I am running Ubuntu 14.04.

The Problem:
I noticed that my PHP-CLI version was running php7.0 but php_info() (the web version) was displaying php 5.5.9. Even though php_info() said pdo was enabled, using the command line (CLI) wasn’t recognizing the pdo_mysql command. It turns out that mysql was enabled for my old version but not the CLI version. All I did was install mysql for php7.0 and it was able to work.

This is what worked:

To check the version:

php -v

To install mysql for php7.0

sudo apt-get install php7.0-mysql

1) make sure your CLI version is the same as your web version
2) If they are different, make sure your CLI version has the mysql plug-in since it doesn’t come with it as a default.

answered Jan 4, 2017 at 20:31

Growling Flea's user avatar

The problem is a missing php to mysql library. In CentOs i fixed it by running
# yum install php-mysql and then restarting apache with # /bin/systemctl restart httpd.service Note that the naming is slightly different from debian/ubuntu based distros, php->php5 and httpd->apache2.

answered Dec 8, 2015 at 6:36

Japheth Ongeri - inkalimeva's user avatar

I extremely recommend mysqllnd instead of mysql because of you would have a lot of problems like number converting and bit type evaluates problem with mysql extension.

on ubuntu install mysqllnd with following command:

sudo apt-get install php5-mysqlnd

answered Sep 17, 2016 at 17:21

MSS's user avatar

MSSMSS

3,56025 silver badges29 bronze badges

In my case, I was using PDO with php-cli, and it worked fine.

Only when I tried to connect from apache, I got the «missing driver» issue, which I didn’t quite understand.

A simple apt-get install php-mysql solved it. (Ubuntu 16.04 / PHP7. credits go to the selected answer & Ivan’s comment)

Hope it can help.

answered Oct 31, 2016 at 14:46

Balmipour's user avatar

BalmipourBalmipour

2,9851 gold badge25 silver badges28 bronze badges

PHP Fatal error:  Uncaught PDOException: could not find driver

I struggled and struggled with «apt install php-mysql php7toInfinity and don’t forget sqlite-what-ever’s» and just could not get rid of this error message until I went back to basics and reset the file-permissions on the web-site in question.

These 3 commands reset file and folder permissions on the web-site and got it to work again.

cd /var/www/web-site-name.com/web/

# find (sub) directories and change permissions
find . -type d -exec chmod 755 {} \;

# find files and change permissions
find . -type f -exec chmod 664 '{}' \;

answered Aug 18, 2019 at 18:48

SamTzu's user avatar

SamTzuSamTzu

1671 silver badge7 bronze badges

I Fixed this issue on my Debian 6.
Normally I just had installed php5-common package. After installation, you have to restart your web server (apache or nginx depending on which one you installed).
Then I just do an lsof on the apache process id (lsof -p process_id) as followed :

sudo lsof -p 1399   #replace 1399 by your apache process id
apache2 1399 root  mem    REG  254,2    80352 227236 /usr/lib/php5/20090626/xmlrpc.so
apache2 1399 root  mem    REG  254,2   166496 227235 /usr/lib/php5/20090626/suhosin.so
apache2 1399 root  mem    REG  254,2    31120 227233 /usr/lib/php5/20090626/pdo_mysql.so
apache2 1399 root  mem    REG  254,2   100776 227216 /usr/lib/php5/20090626/pdo.so
apache2 1399 root  mem    REG  254,2   135864 227232 /usr/lib/php5/20090626/mysqli.so

As you can see above, the modules are installed on a file path not known or guided by common library path: /usr/lib/php5/20090626/. For your installation, it may be different, but only the path of pdo_mysql.so, pdo.so, mysqli.so. So, this is why Drupal or any other php engine couldn’t find the library and shows that error: PDOException: could not find driver

I just don’t know why it is installed on such a weird path, for me it’s just a bug in the library package installation script in debian 6.
I solved the issue by creating a symbolic for all the files under /usr/lib/php5/20090626/ to
/usr/lib/php5/ with this command :

ln -s /usr/lib/php5/20090626/* /usr/lib/php5/

fvrghl's user avatar

fvrghl

3,6325 gold badges28 silver badges36 bronze badges

answered Nov 8, 2012 at 17:20

douggynix's user avatar

douggynixdouggynix

1412 silver badges2 bronze badges

1

$DB_TYPE = 'mysql'; //Type of database<br>
$DB_HOST = 'localhost'; //Host name<br>
$DB_USER = 'root'; //Host Username<br>
$DB_PASS = ''; //Host Password<br>
$DB_NAME = 'database_name'; //Database name<br><br>

$dbh = new PDO("$DB_TYPE:host=$DB_HOST; dbname=$DB_NAME;", $DB_USER, $DB_PASS); // PDO Connection

This worked for me.

fvrghl's user avatar

fvrghl

3,6325 gold badges28 silver badges36 bronze badges

answered Jun 3, 2013 at 3:18

Persianuser's user avatar

1

I faced the same issue after I removed the php5 package (that includes all the drivers as well) in order to install php7 package. I actually installed php7 package without a mysql module.

I managed to solve it by typing in the terminal:

1) $ apt-cache search php7
which lists all the modules, looking through the modules I found,

php7.0-mysql — MySQL module for PHP

2) $ sudo apt-get install php7.0-mysql

That’s it. It worked for me in my linux system.

(use the appropriate php version, yours could be php5)

answered May 10, 2016 at 12:38

Roshimon's user avatar

RoshimonRoshimon

1,99119 silver badges16 bronze badges

Just one other thing to confirm as some people are copy/pasting example code from the Internet to get started. Make sure you have MySQL entered here:

... $dbh = new PDO ("mysql: ...  

In some examples this shows

$dbh = new PDO ("dblib ...

Dimitar's user avatar

Dimitar

4,4224 gold badges31 silver badges47 bronze badges

answered Jun 29, 2016 at 3:49

Joe's user avatar

For those using Symfony2/3 and wondering why you’re getting this error. If you’re using «mapping_types», you might encounter this error. The reason is that «mapping_types» is placed at the wrong level. For instance :

doctrine:
  dbal:
    mapping_types:
        set: string

This «mapping_types» must be placed at this level :

doctrine:
dbal:
    #To counter the error caused by 'mapping_types'
    connections:
        default:
            server_version: %database_server_version%
            mapping_types:
                set: string

I hope this helps

I found the solution here : https://github.com/doctrine/DoctrineBundle/issues/327

answered Feb 17, 2017 at 20:07

aneth101's user avatar

aneth101aneth101

5095 silver badges9 bronze badges

Everywhere I go I read that the path of extension_dir should be changed from ext to an absolute path. It worked for me. However, when trying to build a server of my colleague’s PC, I had to let the value to ext instead of putting an absolute path.

If you did put an absolute path and it does the extension is still not found, considerer trying both with the absolute path and ext.

answered Feb 13, 2018 at 10:42

papillon's user avatar

papillonpapillon

1,8173 gold badges19 silver badges40 bronze badges

Check correct path in extension_dir in you phpinfo().

answered May 29, 2019 at 19:42

Alexandr Nizhnik's user avatar

Had the same issue, because I forgot to go into my virtual machine. If I go to my local directory like this:

cd /www/homestead/my_project
php artisan migrate

that error will appear. But it works on my virtual machine

cd ~/homestead
vagrant ssh   
cd /www/homestead/my_project
php artisan migrate

answered Jun 21, 2019 at 7:16

Adam's user avatar

AdamAdam

26.1k22 gold badges158 silver badges247 bronze badges

I have just installed Debian Lenny with Apache, MySQL, and PHP and I am receiving a PDOException could not find driver.

This is the specific line of code it is referring to:

$dbh = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASS)

DB_HOST, DB_NAME, DB_USER, and DB_PASS are constants that I have defined. It works fine on the production server (and on my previous Ubuntu Server setup).

Is this something to do with my PHP installation?

Searching the internet has not helped, all I get is experts-exchange and examples, but no solutions.

ghbarratt's user avatar

ghbarratt

11.5k4 gold badges41 silver badges41 bronze badges

asked May 17, 2010 at 20:57

Mike Moore's user avatar

8

You need to have a module called pdo_mysql. Looking for following in phpinfo(),

pdo_mysql

PDO Driver for MySQL, client library version => 5.1.44

answered May 17, 2010 at 21:33

ZZ Coder's user avatar

ZZ CoderZZ Coder

74.5k29 gold badges137 silver badges169 bronze badges

10

The dsn in your code reveals you are trying to connect with the mysql driver. Your error message indicates that this driver is unavailable.

Check that you have the mysql extension installed on your server.

In Ubuntu/Debian you check for the package with:

dpkg --get-selections | grep php | grep mysql

Install the php5-mysql package if you do not have it.

In Ubuntu/Debian you can use:

  • PHP5: sudo apt-get install php5-mysql
  • PHP7: sudo apt-get install php7.0-mysql

Lastly, to get it working, you will need to restart your web-server:

  • Apache: sudo /etc/init.d/apache2 restart
  • Nginx: sudo /etc/init.d/nginx restart

answered Nov 10, 2011 at 5:21

ghbarratt's user avatar

ghbarrattghbarratt

11.5k4 gold badges41 silver badges41 bronze badges

2

Update: newer versions should use php-sqlite3 package instead of php5-sqlite. So use this, if you are using a recent ubuntu version:

sudo apt-get install sqlite php-sqlite3

Original answer to question is here:

sudo apt-get install sqlite php5-sqlite
sudo /etc/init.d/apache2 restart

If your phpinfo() is not showing the pdo_sqlite line (in my case, on my Ubuntu Server), you just need to run the lines above and then you’ll be good to go.

answered Aug 27, 2010 at 18:39

Sudipta Chatterjee's user avatar

8

For newer versions of Ubuntu that have PHP 7.0 you can get the php-mysql package:

sudo apt-get install php-mysql

Then restart your server:

sudo service apache2 restart

answered Aug 19, 2016 at 6:28

ThomasAFink's user avatar

ThomasAFinkThomasAFink

1,26714 silver badges25 bronze badges

1

I had the same issue. The solution depends on OS. In my case, i have debian, so to solve it:

  • Updated my php version from (php5 to php7)
  • Install php-mysql and php7.0-mysql

    apt-get install php-mysql
    apt-get install php7.0-mysql
    
  • I edited my php.ini locate at /etc/php/7.0/apache2/php.ini

    uncomment the line : extension=php_pdo_mysql.dll
    
  • Then restart apache:

    service apache2 restart
    

This solves my problem

Community's user avatar

answered Jun 5, 2017 at 1:26

onlyme's user avatar

onlymeonlyme

3,8062 gold badges23 silver badges17 bronze badges

1

On my Windows machine, I had to give the absolute path to the extension dir in my php.ini:

extension_dir = "c:\php5\ext"

fvrghl's user avatar

fvrghl

3,6325 gold badges28 silver badges36 bronze badges

answered Jun 10, 2013 at 22:41

berdzi's user avatar

berdziberdzi

2613 silver badges2 bronze badges

2

Check if the module is available with php -m | grep pdo_mysql.

If not, for PHP 7.2, you can install relevant package with sudo apt install php7.2-mysql.

Use similar command on other PHP versions and package managers.

answered Jul 4, 2019 at 5:30

Pratik's user avatar

PratikPratik

9591 gold badge14 silver badges20 bronze badges

On Ubuntu just execute

sudo apt-get install php5-mysql

answered Apr 16, 2013 at 13:22

Dmitry Sobolev's user avatar

2

sudo apt-get install php-mysql 

worked well on ubuntu and php 7

answered May 12, 2016 at 9:11

Moses Nandwa's user avatar

1

When adding these into your php.ini ensure the php_pdo.dll reference is first before the db drivers dlls otherwise this will also cause this error message too. Add them like this:

[PHP_PDO]
extension=php_pdo.dll
[PHP_PDO_MYSQL]
extension=php_pdo_mysql.dll

Luís Cruz's user avatar

Luís Cruz

14.8k16 gold badges68 silver badges100 bronze badges

answered Nov 17, 2014 at 23:33

Paul Foster's user avatar

1

for Windows 8.1/10 in :\\php.ini file you should uncomment line «extension=pdo_mysql»

answered Dec 19, 2017 at 16:18

Egor Doynikov's user avatar

Did you check your php.ini (check for the correct location with phpinfo()) if MySQL and the driver is installed correctly?

answered May 17, 2010 at 21:08

cem's user avatar

cemcem

3,3211 gold badge18 silver badges23 bronze badges

1

For PHP 5.5 on CentOS I fixed this by installing the php55-mysqlnd package.

sudo yum -y install php55w-mysqlnd # For Webtatic
sudo yum -y install php55u-mysqlnd # For Remi

For help installing, write a comment as it depends on the way PHP is installed on your system. Available repo’s are webtatic and remi.

answered Jul 23, 2014 at 9:22

SimonW's user avatar

SimonWSimonW

6,1854 gold badges33 silver badges39 bronze badges

I had the same problem during running tests with separate php.ini. I had to add these lines to my own php.ini file:

[PHP]
extension = mysqlnd.so
extension = pdo.so
extension = pdo_mysql.so

Notice: Exactly in this order

answered Jul 23, 2016 at 15:04

Facedown's user avatar

FacedownFacedown

1921 gold badge2 silver badges10 bronze badges

0

Incorrect installation of PHP was being called

I was experiencing the same problem. And I hope this would help someone who is having a similar issue as me.

Scenario

OS = Windows 10  
Platform = XAMPP  
PHP Version = 7 (Multiple Version seem to have been installed in the PC)  

I created phpinfo.php file in the public folder and run the phpinfo() to look for the location of my php.ini file.

PHP.ini Location = c:\xampp\php\php.ini

Problem
Calling c:\xampp\htdocs> php -v returned PHP 7.2.3 but phpinfo.php showed PHP 7.2.2.

Solution
Instead of calling

php artisan migrate:install   

which gave me this error, I used

c:\xampp\php\php artisan migrate:install

and it worked.

answered Sep 21, 2018 at 10:21

RealSollyM's user avatar

RealSollyMRealSollyM

1,5301 gold badge22 silver badges35 bronze badges

Check if extension_dir in php configuration file set correctly. Try to comment/uncomment some extensions and see if it’s reflected on phpinfo().
If it doesn’t then either php config file cannot be loaded (wrong location) extension_dir is commented or set to the wrong location.

answered Aug 18, 2012 at 14:02

hserge's user avatar

hsergehserge

9051 gold badge9 silver badges12 bronze badges

In my case my DSN string was incorrect, specifically it did not contain mysql://. I would have expected a different error message, perhaps something like ‘DSN string does not specify driver/protocol.’

Adding mysql:// to the beginning of the DSN string resolved the issue.

random_user_name's user avatar

answered Jun 21, 2012 at 16:38

gposton's user avatar

I spent the last day trying to figure out why I was getting the following error. I am running Ubuntu 14.04.

The Problem:
I noticed that my PHP-CLI version was running php7.0 but php_info() (the web version) was displaying php 5.5.9. Even though php_info() said pdo was enabled, using the command line (CLI) wasn’t recognizing the pdo_mysql command. It turns out that mysql was enabled for my old version but not the CLI version. All I did was install mysql for php7.0 and it was able to work.

This is what worked:

To check the version:

php -v

To install mysql for php7.0

sudo apt-get install php7.0-mysql

1) make sure your CLI version is the same as your web version
2) If they are different, make sure your CLI version has the mysql plug-in since it doesn’t come with it as a default.

answered Jan 4, 2017 at 20:31

Growling Flea's user avatar

The problem is a missing php to mysql library. In CentOs i fixed it by running
# yum install php-mysql and then restarting apache with # /bin/systemctl restart httpd.service Note that the naming is slightly different from debian/ubuntu based distros, php->php5 and httpd->apache2.

answered Dec 8, 2015 at 6:36

Japheth Ongeri - inkalimeva's user avatar

I extremely recommend mysqllnd instead of mysql because of you would have a lot of problems like number converting and bit type evaluates problem with mysql extension.

on ubuntu install mysqllnd with following command:

sudo apt-get install php5-mysqlnd

answered Sep 17, 2016 at 17:21

MSS's user avatar

MSSMSS

3,56025 silver badges29 bronze badges

In my case, I was using PDO with php-cli, and it worked fine.

Only when I tried to connect from apache, I got the «missing driver» issue, which I didn’t quite understand.

A simple apt-get install php-mysql solved it. (Ubuntu 16.04 / PHP7. credits go to the selected answer & Ivan’s comment)

Hope it can help.

answered Oct 31, 2016 at 14:46

Balmipour's user avatar

BalmipourBalmipour

2,9851 gold badge25 silver badges28 bronze badges

PHP Fatal error:  Uncaught PDOException: could not find driver

I struggled and struggled with «apt install php-mysql php7toInfinity and don’t forget sqlite-what-ever’s» and just could not get rid of this error message until I went back to basics and reset the file-permissions on the web-site in question.

These 3 commands reset file and folder permissions on the web-site and got it to work again.

cd /var/www/web-site-name.com/web/

# find (sub) directories and change permissions
find . -type d -exec chmod 755 {} \;

# find files and change permissions
find . -type f -exec chmod 664 '{}' \;

answered Aug 18, 2019 at 18:48

SamTzu's user avatar

SamTzuSamTzu

1671 silver badge7 bronze badges

I Fixed this issue on my Debian 6.
Normally I just had installed php5-common package. After installation, you have to restart your web server (apache or nginx depending on which one you installed).
Then I just do an lsof on the apache process id (lsof -p process_id) as followed :

sudo lsof -p 1399   #replace 1399 by your apache process id
apache2 1399 root  mem    REG  254,2    80352 227236 /usr/lib/php5/20090626/xmlrpc.so
apache2 1399 root  mem    REG  254,2   166496 227235 /usr/lib/php5/20090626/suhosin.so
apache2 1399 root  mem    REG  254,2    31120 227233 /usr/lib/php5/20090626/pdo_mysql.so
apache2 1399 root  mem    REG  254,2   100776 227216 /usr/lib/php5/20090626/pdo.so
apache2 1399 root  mem    REG  254,2   135864 227232 /usr/lib/php5/20090626/mysqli.so

As you can see above, the modules are installed on a file path not known or guided by common library path: /usr/lib/php5/20090626/. For your installation, it may be different, but only the path of pdo_mysql.so, pdo.so, mysqli.so. So, this is why Drupal or any other php engine couldn’t find the library and shows that error: PDOException: could not find driver

I just don’t know why it is installed on such a weird path, for me it’s just a bug in the library package installation script in debian 6.
I solved the issue by creating a symbolic for all the files under /usr/lib/php5/20090626/ to
/usr/lib/php5/ with this command :

ln -s /usr/lib/php5/20090626/* /usr/lib/php5/

fvrghl's user avatar

fvrghl

3,6325 gold badges28 silver badges36 bronze badges

answered Nov 8, 2012 at 17:20

douggynix's user avatar

douggynixdouggynix

1412 silver badges2 bronze badges

1

$DB_TYPE = 'mysql'; //Type of database<br>
$DB_HOST = 'localhost'; //Host name<br>
$DB_USER = 'root'; //Host Username<br>
$DB_PASS = ''; //Host Password<br>
$DB_NAME = 'database_name'; //Database name<br><br>

$dbh = new PDO("$DB_TYPE:host=$DB_HOST; dbname=$DB_NAME;", $DB_USER, $DB_PASS); // PDO Connection

This worked for me.

fvrghl's user avatar

fvrghl

3,6325 gold badges28 silver badges36 bronze badges

answered Jun 3, 2013 at 3:18

Persianuser's user avatar

1

I faced the same issue after I removed the php5 package (that includes all the drivers as well) in order to install php7 package. I actually installed php7 package without a mysql module.

I managed to solve it by typing in the terminal:

1) $ apt-cache search php7
which lists all the modules, looking through the modules I found,

php7.0-mysql — MySQL module for PHP

2) $ sudo apt-get install php7.0-mysql

That’s it. It worked for me in my linux system.

(use the appropriate php version, yours could be php5)

answered May 10, 2016 at 12:38

Roshimon's user avatar

RoshimonRoshimon

1,99119 silver badges16 bronze badges

Just one other thing to confirm as some people are copy/pasting example code from the Internet to get started. Make sure you have MySQL entered here:

... $dbh = new PDO ("mysql: ...  

In some examples this shows

$dbh = new PDO ("dblib ...

Dimitar's user avatar

Dimitar

4,4224 gold badges31 silver badges47 bronze badges

answered Jun 29, 2016 at 3:49

Joe's user avatar

For those using Symfony2/3 and wondering why you’re getting this error. If you’re using «mapping_types», you might encounter this error. The reason is that «mapping_types» is placed at the wrong level. For instance :

doctrine:
  dbal:
    mapping_types:
        set: string

This «mapping_types» must be placed at this level :

doctrine:
dbal:
    #To counter the error caused by 'mapping_types'
    connections:
        default:
            server_version: %database_server_version%
            mapping_types:
                set: string

I hope this helps

I found the solution here : https://github.com/doctrine/DoctrineBundle/issues/327

answered Feb 17, 2017 at 20:07

aneth101's user avatar

aneth101aneth101

5095 silver badges9 bronze badges

Everywhere I go I read that the path of extension_dir should be changed from ext to an absolute path. It worked for me. However, when trying to build a server of my colleague’s PC, I had to let the value to ext instead of putting an absolute path.

If you did put an absolute path and it does the extension is still not found, considerer trying both with the absolute path and ext.

answered Feb 13, 2018 at 10:42

papillon's user avatar

papillonpapillon

1,8173 gold badges19 silver badges40 bronze badges

Check correct path in extension_dir in you phpinfo().

answered May 29, 2019 at 19:42

Alexandr Nizhnik's user avatar

Had the same issue, because I forgot to go into my virtual machine. If I go to my local directory like this:

cd /www/homestead/my_project
php artisan migrate

that error will appear. But it works on my virtual machine

cd ~/homestead
vagrant ssh   
cd /www/homestead/my_project
php artisan migrate

answered Jun 21, 2019 at 7:16

Adam's user avatar

AdamAdam

26.1k22 gold badges158 silver badges247 bronze badges

Laravel is a popular open-source PHP web framework used for building modern web applications. When using PostgreSQL as the database backend for Laravel, you may encounter the error «Could not Find Driver.» This error occurs when the PDO (PHP Data Object) extension, which Laravel uses to interact with databases, is not installed or configured correctly.

Method 1: Installing the PDO extension for PostgreSQL

To fix the error «[PDOException]: Could not Find Driver in PostgreSQL» in Laravel, you can install the PDO extension for PostgreSQL. Here are the steps:

  1. Install the PostgreSQL driver for PHP:
sudo apt-get install php-pgsql
  1. Install the PDO extension for PostgreSQL:
sudo apt-get install php7.4-pdo-pgsql
  1. Restart the Apache server:
sudo service apache2 restart
  1. Check if the PDO extension for PostgreSQL is installed:
  1. If the output is «pdo_pgsql», then the installation is successful.

  2. If you still encounter the same error, you can add the following code to your Laravel database configuration file (config/database.php):

'pgsql' => [
    'driver' => 'pgsql',
    'host' => env('DB_HOST', '127.0.0.1'),
    'port' => env('DB_PORT', '5432'),
    'database' => env('DB_DATABASE', 'forge'),
    'username' => env('DB_USERNAME', 'forge'),
    'password' => env('DB_PASSWORD', ''),
    'charset' => 'utf8',
    'prefix' => '',
    'schema' => 'public',
    'sslmode' => 'prefer',
],
  1. Save the file and run the following command to clear the configuration cache:
  1. Try to run your Laravel application again and see if the error has been fixed.

That’s it! By following these steps, you should be able to fix the error «[PDOException]: Could not Find Driver in PostgreSQL» in Laravel by installing the PDO extension for PostgreSQL.

Method 2: Checking the Configuration of PDO Driver for PostgreSQL

To check the configuration of PDO Driver for PostgreSQL, follow these steps:

  1. Open your php.ini file and uncomment the following line:
  1. Save and close the file.

  2. Restart your web server.

  3. Check if the PDO_PGSQL driver is loaded by running the following code:

<?php
print_r(PDO::getAvailableDrivers());
?>

This should output an array that includes «pgsql».

  1. If the driver is still not loaded, check if the PostgreSQL extension is installed by running the following code:
<?php
echo extension_loaded('pgsql') ? 'yes':'no';
?>

If the output is «no», you need to install the PostgreSQL extension.

  1. If you have installed the PostgreSQL extension but still can’t find the driver, make sure that the extension directory is added to your system’s PATH environment variable.

  2. Finally, make sure that you have the correct credentials and connection settings in your Laravel configuration file for PostgreSQL.

That’s it! By following these steps, you should be able to fix the «PDOException: Could not Find Driver in PostgreSQL» error in Laravel.

Method 3: Enabling the PDO Driver for PostgreSQL in PHP Configuration

To enable the PDO driver for PostgreSQL in PHP configuration, you can follow these steps:

  1. Install the PostgreSQL driver for PHP by running the following command:
sudo apt-get install php-pgsql
  1. Once the driver is installed, open your php.ini file and uncomment the following line:
  1. Restart your web server to apply the changes.
sudo systemctl restart apache2
  1. Test the connection to your PostgreSQL database using the following PHP code:
try {
    $pdo = new PDO('pgsql:host=localhost;dbname=mydatabase', 'myusername', 'mypassword');
    echo "Connected to the database successfully!";
} catch (PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
}

Make sure to replace mydatabase, myusername, and mypassword with your actual database name, username, and password.

  1. If the connection is successful, you can now use the PDO driver for PostgreSQL in your Laravel application.

That’s it! By enabling the PDO driver for PostgreSQL in PHP configuration, you should be able to fix the Laravel error [PDOException]: Could not Find Driver.

Привет

Пытаюсь выполнить данную команду из корня проекта zf2:
vendor\bin\doctrine-module orm:validate-schema

Результат работы команды:

[Mapping]  OK - The mapping files are correct.
  [PDOException]
  could not find driver
orm:validate-schema

Юзал поиск, но толкового ничего не нашел.

Были такие варианты, как проблемы с конфиг файлом. Вот мой конфиг:

<?php
return array(
    'doctrine' => array(
        'connection' => array(
            'orm_default' => array(
                'driverClass' =>'Doctrine\DBAL\Driver\PDOMySql\Driver',
                'params' => array(
                    'host'     => 'localhost',
                    'port'     => '3306',
                    'user'     => 'root',
                    'password' => '',
                    'dbname'   => 'ZF2_Test',
                )
            )
        ),
    ),
);

Все путем + есть другой модуль, который работает с ORM Doctrine и он работает без каких-либо проблем.

Были варианты с неподключенным расширением extension=php_pdo_mysql.dll в php.ini файле. Он у меня подключен в Php.ini + phpinfo() показывает, что PDO включено.

В итоге так и не нашел решения данной проблемы. Что может вызывать эту ошибку и как ее решать?

Спасибо

Перейти к содержимому

Заметил как-то следующую ошибку:

PDOException «could not find driver»

Причиной может быть не активированный pdo_mysql либо не установлено php5-mysql.
Посмотрим информацию о PDO:

php -i|grep PDO

В php.ini или подключенных файлах конфигурации должны быть строки:

extension=pdo.so
extension=pdo_mysql.so

Посмотрим информацию о php5-mysql:

dpkg --get-selections | grep php5-mysql

Если не установлен, то установим, в Ubuntu это можно сделать например так:

sudo apt-get install php5-mysql
sudo apt-get install php-mysql
sudo /etc/init.d/apache2 restart
sudo service apache2 restart

Понравилась статья? Поделить с друзьями:
  • Ошибка code actros
  • Ошибка could not find a needed package 1004
  • Ошибка chevrolet lacetti 0342
  • Ошибка chrome 1603
  • Ошибка chrome 0xc0000409