Laravel: Error [PDOException]: Driver not found in PostgreSQL
P粉722409996
2023-07-31 18:16:43
<p>Translate: "I'm trying to connect to a PostgreSQL database via Laravel in order to execute the php artisan migrate command, but it doesn't seem to be successful because it's reading the MySQL database name.<br /><br /> ;The following are the commands in database.php:</p><p><br /></p>
<pre class="brush:php;toolbar:false;">'connections' => array(
'sqlite' => array(
'driver' => 'sqlite',
'database' => __DIR__.'/../database/production.sqlite',
'prefix' => '',
),
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
'pgsql' => array(
'driver' => 'pgsql',
'host' => 'localhost',
'database' => 'postgres',
'username' => 'postgres',
'password' => 'root',
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
),
'sqlsrv' => array(
'driver' => 'sqlsrv',
'host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' => '',
'prefix' => '',
),
),</pre>
<p>If I remove the path to MySQL, I get: </p>
<pre class="brush:php;toolbar:false;">[InvalidArgumentException]
Database [mysql] not configured.</pre>
<p><br /></p><hr />
<strong>Translate: "Edit: I encountered a 'PDOException: could not find driver' error when trying to execute the php artisan migrate command. I'm using WAMP and on Windows 8.1. The database is using PostgreSQL."< /strong><p><br /></p>
<p><br /></p><hr />
<strong>EDIT:</strong> Translate: "I have tried a series of alternative solutions but the problem is still not resolved. Have checked php.ini in Apache, WAMP (from php folder) and PostgreSQL File.extension_dir is set correctly as shown below -> extension_dir = "c:/wamp/bin/php/php5.5.12/ext/". extension=pdo_pgsql.dll and extension=pgsql.dll have been uncommented.< br /><br />Have set the PATH in the 'System Variables' and restarted the computer. But still no success.<br /><br />Thanks for the help so far. <br /><br />This is my driver php_pdo_driver.h and php_pdo.h located in C:Program Files (x86)PostgreSQLEnterpriseDB-ApachePHPphpSDKincludeextpdo<br /><br />From phpinfo Information obtained: <br /><p><br /></p>
<blockquote>
<p>Translate: "PHP version 5.5.12<br /><br />Compiler MSVC11 (Visual C 2012) configuration 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""</p><p>< ;br /></p>
</blockquote><p><br /></p>
"For PDOException: could not find driver for MySQL error, if it is a Debian-based operating system
Translate: "Be sure to configure the 'default' key in app/config/database.php.
For PostgreSQL, the configuration should be 'default' => 'postgres'.
If you receive a [PDOException] could not find driver error, check that you have the correct PHP extensions installed. You need to install and enable pdo_pgsql.so and pgsql.so. How to install these extensions varies by operating system.
For Windows, the pgsql extension should already be pre-downloaded with the official PHP distribution. Just edit your php.ini file and uncomment the following lines extension=pdo_pgsql.so and extension=pgsql.so.
Also, in php.ini, make sure extension_dir is set to the correct directory. It should be a folder named extensions or ext or similar in your PHP installation directory.
Finally, add libpq. dll from C:\wamp\bin\php\php5.*\ to C:\wamp\bin\apache*\bin and restart all services through the WampServer interface.
If the exception still occurs, you You may need to add PostgreSQL's \bin directory to your PATH environment variable."
This should solve any problem. For more information see: