Active1 month ago
SOLVEDLaravel: PDOException: could not find driver I am developing a website on a server I only have access to MySQL and FTP, so all commands I run are through the b374k php shell. I am experiencing a Laravel problem with SQL driver. Illuminate Database QueryException could not find driver (SQL: select. from informationschema.tables where tableschema = test and tablename = migrations) PDOException 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.
ghbarratt9,66844 gold badges3636 silver badges4141 bronze badges
Mike MooreMike Moore3,06388 gold badges3434 silver badges6161 bronze badges
38 Answers
12 next
You need to have a module called pdo_mysql. Looking for following in phpinfo(),
ZZ CoderZZ Coder62.7k2626 gold badges122122 silver badges156156 bronze badges
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:
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
9,66844 gold badges3636 silver badges4141 bronze badges
Update: newer versions should use
php-sqlite3
package instead of php5-sqlite
. So use this, if you are using a recent ubuntu version:Original answer to question is here:
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.
Sudipta ChatterjeeSudipta Chatterjee3,45511 gold badge2222 silver badges3030 bronze badges
For newer versions of Ubuntu that have PHP 7.0 you can get the
php-mysql
package:Then restart your server:
ThomasAFinkThomasAFink
On my Windows machine, I had to give the absolute path to the extension dir in my php.ini:
extension_dir = 'c:php5ext'
2,19322 gold badges2222 silver badges3434 bronze badges
berdziberdzi
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
- I edited my
php.ini
locate at /etc/php/7.0/apache2/php.ini - Then restart apache:
This solves my problem
Community♦
onlymeonlyme1,50411 gold badge1111 silver badges1010 bronze badges
Dmitry SobolevDmitry Sobolev
Moses NandwaMoses Nandwa
Did you check your php.ini (check for the correct location with phpinfo()) if MySQL and the driver is installed correctly?
cemcem2,95611 gold badge1414 silver badges2323 bronze badges
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:
Luís Cruz11.9k1212 gold badges5454 silver badges7878 bronze badges
Paul FosterPaul Foster
For
PHP 5.5
on CentOS
I fixed this by installing the php55-mysqlnd
package.For help installing, write a comment as it depends on the way PHP is installed on your system. Available repo's are
SimonWSimonWwebtatic
and remi
.4,40633 gold badges2323 silver badges3434 bronze badges
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.
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:
To install mysql for php7.0
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.
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.
Growling FleaGrowling Flea
for Windows 8.1/10 in :php.ini file you should uncomment line 'extension=pdo_mysql'
Egor DoynikovEgor Doynikov
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.
PratikPratik40011 gold badge55 silver badges1515 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.
hsergehserge
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
cale_bmysql://
to the beginning of the DSN string resolved the issue.21k77 gold badges5454 silver badges8989 bronze badges
gpostongposton
The problem is a missing php to mysql library. In CentOs i fixed it by running
Japheth Ongeri - inkalimevaJapheth Ongeri - inkalimeva# 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.2,95166 gold badges2323 silver badges4343 bronze badges
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:MSSMSS
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 :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/
2,19322 gold badges2222 silver badges3434 bronze badges
douggynixdouggynix
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 php7which 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)
RoshimonRoshimon
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:
In some examples this shows
dim82,71644 gold badges2222 silver badges4141 bronze badges
JoeJoe
I had the same problem during running tests with separate php.ini. I had to add these lines to my own php.ini file:
Notice: Exactly in this order
FacedownFacedown
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.
BalmipourBalmipour
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 :
This 'mapping_types' must be placed at this level :
I hope this helps
I found the solution here : https://github.com/doctrine/DoctrineBundle/issues/327
aneth101aneth101
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
.papillonpapillon
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
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:xamppphpphp.ini
Problem
Calling
Calling
c:xampphtdocs> php -v
returned PHP 7.2.3
but phpinfo.php
showed PHP 7.2.2
. Solution
Instead of calling
Instead of calling
which gave me this error, I used
and it worked.
SollyMSollyM1,03711 gold badge1414 silver badges2929 bronze badges
Check correct path in extension_dir in you phpinfo().
Alexandr NizhnikAlexandr Nizhnik
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.
SamTzuSamTzu
fvrghl2,19322 gold badges2222 silver badges3434 bronze badges
PersianuserPersianuser
I had the same exception when trying to use
pdo_sqlite
. The problem was that the automatically created 20-pdo_sqlite.ini
and 20-sqlite3.ini
symlinks (in /etc/php5/mods-enabled
) were broken.Removeing the broken symlinks and adding them manually with:
sudo ln -s /etc/php5/mods-avaliable/pdo_sqlite.ini /etc/php5/mods-enabled/20-pdo_sqlite.ini
sudo ln -s /etc/php5/mods-avaliable/sqlite3.ini /etc/php5/mods-enabled/20-sqlite3.ini
fixed the problem.
Note: this won't work for older php versions as they did not look for configs in
ioleoioleo/etc/php5/mods-enabled
2,92244 gold badges3838 silver badges5757 bronze badges
protected by Your Common SenseAug 14 at 9:01
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
Would you like to answer one of these unanswered questions instead?
Not the answer you're looking for? Browse other questions tagged phpmysqlpdolamp or ask your own question.
Active2 months ago
I'm trying to connect with PostgreSQL database through Laravel in order to do a php artisan migrate but doesn't seem to be directed since it's reading the database name of MySQL.
Here are the commands from database.php:
If I remove the MySQL paths I'll get:
EDIT:When trying to do php artisan migrate I get a 'PDOException: could not find driver'. I'm using WAMP and I'm in Win8.1. Using PostgreSQL as database.EDIT:Have experimented a series of alternative solutions but I'm still ought to get this solved.The php.ini
file was checked in Apache, WAMP (from php folder) and PostgreSQL. The extension_dir
is correct as it being ->extension_dir = 'c:/wamp/bin/php/php5.5.12/ext/'
The
extension=pdo_pgsql.dll
and extension=pgsql.dll
are uncommented.Done the
PATH
trick in the 'System Variables' and rebooted. No chance. Thanks for the help so far.
Could Not Find Driver Php Pdo Mssql
These are my drivers
php_pdo_driver.h
& php_pdo.h
from C:Program Files (x86)PostgreSQLEnterpriseDB-ApachePHPphpSDKincludeextpdo
Information from phpinfo:
PHP Version 5.5.12
Compiler MSVC11 (Visual C++ 2012) Configure Command cscript /nologo configure.js '--enable-snapshot-build' '--disable-isapi' '--enable-debug-pack' '--without-mssql' '--without-pdo-mssql' '--without-pi3web' '--with-pdo-oci=C:php-sdkoraclex64instantclient10sdk,shared' '--with-oci8=C:php-sdkoraclex64instantclient10sdk,shared' '--with-oci8-11g=C:php-sdkoraclex64instantclient11sdk,shared' '--enable-object-out-dir=../obj/' '--enable-com-dotnet=shared' '--with-mcrypt=static' '--disable-static-analyze' '--with-pgo'
vbence16.1k88 gold badges5757 silver badges102102 bronze badges
HyperionHyperion35322 gold badges44 silver badges1010 bronze badges
19 Answers
Be sure to configure the
'default'
key in app/config/database.php
For postgres, this would be
'default' => 'postgres',
If you are receiving a
[PDOException] could not find driver
error, check to see if you have the correct PHP extensions installed. You need pdo_pgsql.so
and pgsql.so
installed and enabled. Instructions on how to do this vary between operating systems. For Windows, the
pgsql
extensions should come pre-downloaded with the official PHP distribution. Just edit your php.ini
and uncomment the lines extension=pdo_pgsql.so
and extension=pgsql.so
Also, in
php.ini
, make sure extension_dir
is set to the proper directory. It should be a folder called extensions
or ext
or similar inside your PHP install directory.Finally, copy
libpq.dll
from C:wampbinphpphp5.*
into C:wampbinapache*bin
and restart all services through the WampServer interface.If you still get the exception, you may need to add the postgres
bin
directory to your PATH
:- System Properties -> Advanced tab -> Environment Variables
- In 'System variables' group on lower half of window, scroll through and find the
PATH
entry. - Select it and click Edit
- At the end of the existing entry, put the full path to your postgres bin directory. The bin folder should be located in the root of your postgres installation directory.
- Restart any open command prompts, or to be certain, restart your computer.
This should hopefully resolve any problems. For more information see:
Siavosh1,14244 gold badges1616 silver badges4242 bronze badges
laincelinelainceline
For
Nasif Md. TanjimNasif Md. TanjimPDOException: could not find driver
for MySQL
, and if it is Debian
based OS,1,91144 gold badges1919 silver badges3232 bronze badges
For PHP 7 in Ubuntu you can also do:
So, now you can do not uncomment lines in
php.ini
UPD:I have a same error, so problem was not in driver.I changed my
database.ini
, but every time I saw an error.And I change database config in .env
and errors gone.Святослав ПавленкоСвятослав Павленко
This worked for me:
$ sudo apt-get install php-gd php-mysql
Lucky Lucky
I realize this is an old question but I found it in a Google search so I'm going to go ahead and answer just in case someone else runs across this. I'm on a Mac and had the same issue, but solved it by using HomeBrew. Once you've got it installed, you can just run this command:
And replace the 56 with whatever version of PHP you're using without the decimal point.
Billy BrawnerBilly Brawner
I had the same issue. This is what worked for me.
There are 2 php.ini files:
- C:wampbinapacheapache2.4.9bin
- C:wampbinphpphp5.5.12
NOTE: This is using my version of PHP and Apache, change to what yours are.
The php.ini file located in the both folders is what you need to update, the extentions:
- extension=php_pdo_pgsql.dll
- extension=php_pgsql.dll
These are what you need to uncomment (remove the ; symbol).
Restart both Wamp and the Command Prompt.
Hopefully it will work for you :).
user3293860user3293860
Sujal PatelSujal Patel1,90211 gold badge1212 silver badges3131 bronze badges
For those wanting to use Postgresql on OpenSuse (and co), try the following:
nemesisfixxnemesisfixx7,26166 gold badges4747 silver badges5353 bronze badges
Solved after 3 hours... I am using WAMP (PHP 7.2.4), PostgreSQL 10, Laravel 5.6.29. Loaded PHP extensions (pgsql, pdo_pgsql) from Wampserver 3.3, then I was able to connect to the PostgreSQL server with a simple php testcode from the www directory. But
$ php artisan migrate
still returned PDOException::('could not find driver')
I checked the shell (git bash for windows) with
$ php --ini
, that returned C:wamp64binphpphp7.2.4php.ini instead of c:wamp64binapacheapache2.4.33binphp.ini, loaded by WAMPSo you have to uncomment pgsql and pdo_pgsql extensions also in C:wamp64binphpphp7.2.4php.ini, and then migrate will work ...Jozsa-Csiki Lorant CsabaJozsa-Csiki Lorant Csaba
In Windows 8 PC with Laragon 3.4.0 180809, I faced the same issue. It happened in my case because I updated Laragon and it added a new version of PHP. So in
laragon/bin/php/
I actually had two directories:php-7.1.20-Win32-VC14-x64
php-7.1.7-Win32-VC14-x64
I added
7.1.20
into my PATH
variable. But in my Command Console, running php --ini
was showing that the path actually was fetching from the older one: php-7.1.7-Win32-VC14-x64
. So I deleted the old one (for safety, I put it in Recycle Bin). But Laragon failed to start after that.So, in
laragaon/etc/apache2/mod_php.conf
, I changed the path to the latest PHP version. Then restarted Laragon and the issue is resolved. ?Reference: How to add another PHP version - Laragon Forum
Mayeenul IslamMayeenul Islam1,85044 gold badges2828 silver badges7373 bronze badges
I got this problem too. I have solved this issue already. If u are using Wamp then perform the following steps.
- Go to
wamp64/www/bin/php/php*
(where*
is the php version you are using) - Edit file php and uncomment this line by removing the semicolon:
- Save and restart your Wamp server
If it does not work, please check your
kano.env
and config/database again.3,32311 gold badge1818 silver badges3030 bronze badges
Phantih Phantih
I had the same error on PHP 7.3.7 docker with laravel:
This works for me
This will install the pgsql and pdo_pgsql drivers.
Now run this command to uncomment the lines extension=pdo_pgsql.so and extension=pgsql.so from php.ini
AshAsh
Old thread I know, but I lost a couple of hours of my life with this. You also need to set the DB info in the .env file. You don't have to specify the driver here because the default specified in database.php is used (I think). I was struggling because it had
DB_CONNECTION=mysql
in the .env file and I was using pgsql.Mark DMark D
In my case, I had two versions of PHP installed. So all I had to do was use
$ /opt/lampp/bin/php artisan serve
instead of $ php artisan serve
TejasTejas
I was on shared hosting and there I had to enable all the
Black MambaBlack Mambapdo
4,17722 gold badges3333 silver badges5353 bronze badges
sudo apt-get -y install php*-mysql ( just run this command )
Al Imrun ShowrovAl Imrun Showrov
This worked for me:
I am working with 32bit Ubuntu 14
SiHa3,87866 gold badges1919 silver badges3434 bronze badges
GloBEGloBE
I see you are using Windows. I was not able to fix this with enabling any of the extensions that come with my Windows WAMP Server. I tried PDO_ODBC and others and even found the Microsoft Official PDO_SQLSRV.
The solution for me was to install the PDO_SQLSRV drivers from a 3rd party website. I found the drivers through http://robsphp.blogspot.nl/2012/06/unofficial-microsoft-sql-server-driver.html
I usually don't use DLLs from random websites, but I was desperate and this worked for me. Hoping it might save others numerous hours of frustration.
halfer15.3k77 gold badges6363 silver badges129129 bronze badges
NeoNeo8,35122 gold badges6161 silver badges7171 bronze badges
Using Laravel V 5.5.39 with Php 7.1.12 is working fine, but later (newer) php versions cause the problem. So, change Php version and you will get the solution 100% .
Hashmat WaziriHashmat Waziri