Laravel:错误[PDOException]:在PostgreSQL中找不到驱动程序。

时间:2022-07-29 17:05:16

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.

我试图通过Laravel连接PostgreSQL数据库,以便进行php artisan迁移,但似乎没有被定向,因为它正在读取MySQL的数据库名。

Here are the commands from database.php:

下面是来自database.php的命令:

'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'   => '',
    ),

),

If I remove the MySQL paths I'll get:

如果我删除MySQL路径,我会得到:

[InvalidArgumentException]
Database [mysql] not configured.


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.

扩展= pdo_pgsql。dll和扩展= pgsql。dll是激活的。

Done the PATH trick in the 'System Variables' and rebooted. No chance.

在“系统变量”中完成路径技巧并重新启动。没有机会。

Thanks for the help so far.

到目前为止,谢谢你的帮助。

These are my drivers php_pdo_driver.h & php_pdo.h from C:\Program Files (x86)\PostgreSQL\EnterpriseDB-ApachePHP\php\SDK\include\ext\pdo

这些是我的司机php_pdo_driver。h & php_pdo。h从C:\Program Files (x86)\PostgreSQL\ EnterpriseDB-ApachePHP \ php \ SDK \ \ ext \ pdo

Information from phpinfo:

从phpinfo信息:

PHP Version 5.5.12

PHP版本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-sdk\oracle\x64\instantclient10\sdk,shared" "--with-oci8=C:\php-sdk\oracle\x64\instantclient10\sdk,shared" "--with-oci8-11g=C:\php-sdk\oracle\x64\instantclient11\sdk,shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet=shared" "--with-mcrypt=static" "--disable-static-analyze" "--with-pgo"

编译器MSVC11 (Visual c++ 2012)配置命令cscript /nologo配置。-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --/obj/" " "-启用-com-dotnet=共享"-与-mcrypt=静态" "-去功能化-静态-分析"-与-pgo"

15 个解决方案

#1


45  

Be sure to configure the 'default' key in app/config/database.php

确保在app/config/database.php中配置“默认”键。

For postgres, this would be 'default' => 'postgres',

对于postgres,这将是'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.

如果您正在接收一个[PDOException]无法找到驱动程序错误,请检查是否安装了正确的PHP扩展。你需要pdo_pgsql。所以,pgsql。所以安装和启用。关于如何做到这一点的说明在不同的操作系统中是不同的。

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

对于Windows, pgsql扩展应该在正式的PHP发行版前下载。编辑php。并取消对行扩展=pdo_pgsql的注释。所以和扩展= 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.

同时,在php中。ini,确保将extension_dir设置为正确的目录。它应该是PHP安装目录中名为extensions或ext或类似的文件夹。

Finally, copy libpq.dll from C:\wamp\bin\php\php5.*\ into C:\wamp\bin\apache*\bin and restart all services through the WampServer interface.

最后,libpq副本。dll从C:\ wamp \ bin \ php \ php5。*转到C:\wamp\bin\apache*\bin并通过WampServer接口重新启动所有服务。

If you still get the exception, you may need to add the postgres \bin directory to your PATH:

如果您仍然得到异常,您可能需要将postgres \bin目录添加到您的路径中:

  1. System Properties -> Advanced tab -> Environment Variables
  2. 系统属性->高级选项卡->环境变量
  3. In 'System variables' group on lower half of window, scroll through and find the PATH entry.
  4. 在窗口下半部分的“系统变量”组中,滚动并找到路径条目。
  5. Select it and click Edit
  6. 选择它并单击Edit。
  7. 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.
  8. 在现有条目的末尾,将完整路径放置到postgres bin目录。bin文件夹应该位于postgres安装目录的根目录中。
  9. Restart any open command prompts, or to be certain, restart your computer.
  10. 重新启动任何打开的命令提示符,或者确切地说,重新启动计算机。

This should hopefully resolve any problems. For more information see:

这有望解决任何问题。更多信息见:

#2


41  

For PDOException: could not find driver for MySQL, and if it is Debian based OS,

PDOException:无法找到MySQL的驱动程序,如果是基于Debian的操作系统,

sudo apt-get -y install php5-mysql

#3


15  

For PHP 7 in Ubuntu you can also do:

对于PHP 7,你也可以这样做:

sudo apt-get install php7.0-pgsql

So, now you can do not uncomment lines in php.ini

所以,现在您不能取消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.

我也有同样的错误,所以问题不在驱动程序中。我改变了我的数据库。但每次我看到错误。我在。env中修改了数据库配置,错误消失了。

#4


7  

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:

我知道这是一个老问题,但我是在谷歌搜索中找到的,所以我会继续回答,以防有人遇到这个问题。我用的是Mac电脑,也有同样的问题,但我用自制软件解决了这个问题。安装好后,就可以运行以下命令:

brew install php56-pdo-pgsql

And replace the 56 with whatever version of PHP you're using without the decimal point.

用没有小数点的PHP版本替换56。

#5


5  

This worked for me:

这工作对我来说:

$ sudo apt-get install php-gd php-mysql

$ sudo apt-get install php-gd php-mysql

#6


3  

I had the same issue. This is what worked for me.

我也有同样的问题。这对我起了作用。

There are 2 php.ini files:

有两个php。ini文件:

  • C:\wamp\bin\apache\apache2.4.9\bin
  • C:\ wamp \ bin \ apache \ apache2.4.9 \ bin
  • C:\wamp\bin\php\php5.5.12
  • C:\ wamp \ bin \ php \ php5.5.12

NOTE: This is using my version of PHP and Apache, change to what yours are.

注意:这是使用我的PHP和Apache版本,更改为您的版本。

The php.ini file located in the both folders is what you need to update, the extentions:

php。两个文件夹中的ini文件是您需要更新的,扩展:

  • extension=php_pdo_pgsql.dll
  • 扩展= php_pdo_pgsql.dll
  • extension=php_pgsql.dll
  • 扩展= php_pgsql.dll

These are what you need to uncomment (remove the ; symbol).

这些是您需要取消注释的内容(删除;符号)。

Restart both Wamp and the Command Prompt.

重新启动Wamp和命令提示符。

Hopefully it will work for you :).

希望对你有用:)。

#7


2  

sudo apt-get install php7.1-pgsql

#8


0  

For those wanting to use Postgresql on OpenSuse (and co), try the following:

对于那些想在OpenSuse(和co)上使用Postgresql的用户,请尝试以下方法:

zypper --no-refresh in php5-pgsql

#9


0  

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.

旧线我知道,但我失去了几个小时我的生活与此。您还需要在.env文件中设置DB信息。这里不需要指定驱动程序,因为数据库中指定了默认值。使用php(我认为)。我一直在挣扎,因为它在.env文件中有DB_CONNECTION=mysql,而我使用的是pgsql。

#10


0  

In my case, I had two versions of PHP installed. So all I had to do was use

在我的例子中,我安装了两个版本的PHP。所以我要做的就是使用。

$ /opt/lampp/bin/php artisan serve instead of

$ /opt/lampp/bin/php artisan代替

$ php artisan serve

php工匠为美元

#11


0  

I was on shared hosting and there I had to enable all the pdo

我在共享主机上,我必须启用所有的pdo

Laravel:错误[PDOException]:在PostgreSQL中找不到驱动程序。

#12


-1  

set the default 'default' => 'sqlite';

设置默认的'default' => 'sqlite';

check - http://three.laravel.com/docs/database/config

检查——http://three.laravel.com/docs/database/config

and this - setup PostgreSQL with Laravel in MAMP

这个-设置PostgreSQL与Laravel在MAMP

#13


-1  

This worked for me:

这工作对我来说:

$ sudo apt-get -y install php5.6-pgsql
$ sudo service apache2 restart

I am working with 32bit Ubuntu 14

我正在使用32位的Ubuntu 14

#14


-1  

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.

我看到你在用窗户。我无法通过启用任何与Windows WAMP服务器附带的扩展来修复这个问题。我尝试了PDO_ODBC和其他方法,甚至还发现了Microsoft官方的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

我的解决方案是从第三方网站安装PDO_SQLSRV驱动程序。我通过http://robsphp.blogspot.nl2//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.

我通常不使用随机网站上的dll,但我很绝望,这对我很有效。希望它能拯救别人无数小时的挫败。

#15


-3  

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% .

在Php 7.1.12中使用Laravel v5.5.39可以正常工作,但是稍后(更新的)Php版本会引起问题。因此,更改Php版本,您将得到100%的解决方案。

#1


45  

Be sure to configure the 'default' key in app/config/database.php

确保在app/config/database.php中配置“默认”键。

For postgres, this would be 'default' => 'postgres',

对于postgres,这将是'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.

如果您正在接收一个[PDOException]无法找到驱动程序错误,请检查是否安装了正确的PHP扩展。你需要pdo_pgsql。所以,pgsql。所以安装和启用。关于如何做到这一点的说明在不同的操作系统中是不同的。

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

对于Windows, pgsql扩展应该在正式的PHP发行版前下载。编辑php。并取消对行扩展=pdo_pgsql的注释。所以和扩展= 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.

同时,在php中。ini,确保将extension_dir设置为正确的目录。它应该是PHP安装目录中名为extensions或ext或类似的文件夹。

Finally, copy libpq.dll from C:\wamp\bin\php\php5.*\ into C:\wamp\bin\apache*\bin and restart all services through the WampServer interface.

最后,libpq副本。dll从C:\ wamp \ bin \ php \ php5。*转到C:\wamp\bin\apache*\bin并通过WampServer接口重新启动所有服务。

If you still get the exception, you may need to add the postgres \bin directory to your PATH:

如果您仍然得到异常,您可能需要将postgres \bin目录添加到您的路径中:

  1. System Properties -> Advanced tab -> Environment Variables
  2. 系统属性->高级选项卡->环境变量
  3. In 'System variables' group on lower half of window, scroll through and find the PATH entry.
  4. 在窗口下半部分的“系统变量”组中,滚动并找到路径条目。
  5. Select it and click Edit
  6. 选择它并单击Edit。
  7. 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.
  8. 在现有条目的末尾,将完整路径放置到postgres bin目录。bin文件夹应该位于postgres安装目录的根目录中。
  9. Restart any open command prompts, or to be certain, restart your computer.
  10. 重新启动任何打开的命令提示符,或者确切地说,重新启动计算机。

This should hopefully resolve any problems. For more information see:

这有望解决任何问题。更多信息见:

#2


41  

For PDOException: could not find driver for MySQL, and if it is Debian based OS,

PDOException:无法找到MySQL的驱动程序,如果是基于Debian的操作系统,

sudo apt-get -y install php5-mysql

#3


15  

For PHP 7 in Ubuntu you can also do:

对于PHP 7,你也可以这样做:

sudo apt-get install php7.0-pgsql

So, now you can do not uncomment lines in php.ini

所以,现在您不能取消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.

我也有同样的错误,所以问题不在驱动程序中。我改变了我的数据库。但每次我看到错误。我在。env中修改了数据库配置,错误消失了。

#4


7  

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:

我知道这是一个老问题,但我是在谷歌搜索中找到的,所以我会继续回答,以防有人遇到这个问题。我用的是Mac电脑,也有同样的问题,但我用自制软件解决了这个问题。安装好后,就可以运行以下命令:

brew install php56-pdo-pgsql

And replace the 56 with whatever version of PHP you're using without the decimal point.

用没有小数点的PHP版本替换56。

#5


5  

This worked for me:

这工作对我来说:

$ sudo apt-get install php-gd php-mysql

$ sudo apt-get install php-gd php-mysql

#6


3  

I had the same issue. This is what worked for me.

我也有同样的问题。这对我起了作用。

There are 2 php.ini files:

有两个php。ini文件:

  • C:\wamp\bin\apache\apache2.4.9\bin
  • C:\ wamp \ bin \ apache \ apache2.4.9 \ bin
  • C:\wamp\bin\php\php5.5.12
  • C:\ wamp \ bin \ php \ php5.5.12

NOTE: This is using my version of PHP and Apache, change to what yours are.

注意:这是使用我的PHP和Apache版本,更改为您的版本。

The php.ini file located in the both folders is what you need to update, the extentions:

php。两个文件夹中的ini文件是您需要更新的,扩展:

  • extension=php_pdo_pgsql.dll
  • 扩展= php_pdo_pgsql.dll
  • extension=php_pgsql.dll
  • 扩展= php_pgsql.dll

These are what you need to uncomment (remove the ; symbol).

这些是您需要取消注释的内容(删除;符号)。

Restart both Wamp and the Command Prompt.

重新启动Wamp和命令提示符。

Hopefully it will work for you :).

希望对你有用:)。

#7


2  

sudo apt-get install php7.1-pgsql

#8


0  

For those wanting to use Postgresql on OpenSuse (and co), try the following:

对于那些想在OpenSuse(和co)上使用Postgresql的用户,请尝试以下方法:

zypper --no-refresh in php5-pgsql

#9


0  

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.

旧线我知道,但我失去了几个小时我的生活与此。您还需要在.env文件中设置DB信息。这里不需要指定驱动程序,因为数据库中指定了默认值。使用php(我认为)。我一直在挣扎,因为它在.env文件中有DB_CONNECTION=mysql,而我使用的是pgsql。

#10


0  

In my case, I had two versions of PHP installed. So all I had to do was use

在我的例子中,我安装了两个版本的PHP。所以我要做的就是使用。

$ /opt/lampp/bin/php artisan serve instead of

$ /opt/lampp/bin/php artisan代替

$ php artisan serve

php工匠为美元

#11


0  

I was on shared hosting and there I had to enable all the pdo

我在共享主机上,我必须启用所有的pdo

Laravel:错误[PDOException]:在PostgreSQL中找不到驱动程序。

#12


-1  

set the default 'default' => 'sqlite';

设置默认的'default' => 'sqlite';

check - http://three.laravel.com/docs/database/config

检查——http://three.laravel.com/docs/database/config

and this - setup PostgreSQL with Laravel in MAMP

这个-设置PostgreSQL与Laravel在MAMP

#13


-1  

This worked for me:

这工作对我来说:

$ sudo apt-get -y install php5.6-pgsql
$ sudo service apache2 restart

I am working with 32bit Ubuntu 14

我正在使用32位的Ubuntu 14

#14


-1  

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.

我看到你在用窗户。我无法通过启用任何与Windows WAMP服务器附带的扩展来修复这个问题。我尝试了PDO_ODBC和其他方法,甚至还发现了Microsoft官方的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

我的解决方案是从第三方网站安装PDO_SQLSRV驱动程序。我通过http://robsphp.blogspot.nl2//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.

我通常不使用随机网站上的dll,但我很绝望,这对我很有效。希望它能拯救别人无数小时的挫败。

#15


-3  

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% .

在Php 7.1.12中使用Laravel v5.5.39可以正常工作,但是稍后(更新的)Php版本会引起问题。因此,更改Php版本,您将得到100%的解决方案。