Laravel: Error [PDOException]: Could not Find Driver in PostgreSQL
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:\wamp\bin\php\php5.*\
into C:\wamp\bin\apache*\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:
- http://php.net/manual/en/install.pecl.windows.php
- http://webcheatsheet.com/php/install_and_configure.php#extsetup
I tried using postgresql on laravel but got could not find driver (SQL: select * from users where id = 4 limit 1)
thank you all for your contributions, but I guess my system was the cause because it seems I did everything right initially, what happened was, After I got that error and I was not able to resolve it then, I switched back to MySql and continued with my task, at the end, I needed to restart my system for system update, after restarting, I said I should give the PostgreSql a shot, I edited my .env back to the configuration above, and also run php artisan config:cache, (which I did before) and the error is gone, I am now using PostgreSql with my laravel application.
My Observations
- I need to restart my system after I uncomment pgsql and pdo_pgsql in my php.ini.
- I must stop my WAMPSERVER and also my php artisan serve was running, I should have stopped and restarted them.
PDOException::(could not find driver) laravel pgsql
I found my mistake, this happened because I've been installed postgres separately on my system. I should install it into wamp or xampp.
anyway, I used bitnami wamp stack as server
https://bitnami.com/stack/wapp
Could not find driver (PDO exception with Laravel)
It seems that the php cli has another config file installed elsewhere (the path can be found in phpinfo()). I uncommented the following line, according to madflow and it worked:
;extension=pdo_pgsql -> extension=pdo_pgsql
Laravel: Error [PDOException]: Could not Find Driver (PostgreSQL)
There's not only package php/php5, but also package libapache2-mod-php. Unless you use PHP with mod_cgi, you need to update package libapache2-mod-php too, in order to have the appropriate PHP version in your web server.
As you already noted, there are several PHP config directories and files. If you want to use Postgres and PDO in version 5.6 as well, you must enable it in both config files.
On my system (Ubuntu 16.04), there are subdirectories /etc/php/7.0/cli/conf.d
and /etc/php/7.0/apache2/conf.d
, which both contain 20-pdo_mysql.ini
; configuration for php mysql module
; priority=20
extension=pdo_mysql.so
So you can and must configure Postgres and PDO separately for webserver and/or cli, and for each version.
Laravel: PDOException: could not find driver
You might need to comment out the following in your php.ini file.
;extension=pdo_mysql.so
Taken from this post:
Laravel 5 PDOException Could Not Find Driver
. I think I had to do something exactly like this when setting up laravel on digital ocean.
Related Topics
How to Solve "Fatal Error: Class 'MySQLi' Not Found"
Upload Photo to Album With Facebook'S Graph API
Best Solution to Protect PHP Code Without Encryption
How to Check If a Date Is in a Given Range
Pdo Binding Values For MySQL in Statement
Can Png Image Transparency Be Preserved When Using PHP'S Gdlib Imagecopyresampled
A Non Well Formed Numeric Value Encountered
Where Does PHP'S Error Log Reside in Xampp
Convert Dot Syntax Like "This.That.Other" to Multi-Dimensional Array in PHP
PHP If Statement With Multiple Conditions
MySQLi Equivalent of MySQL_Result()
How to Create a Simple 'Hello World' Module in Magento
PHP, Get File Name Without File Extension
PHP With MySQL 8.0+ Error: the Server Requested Authentication Method Unknown to the Client