php 带有消息“找不到驱动程序”的 PostgreSql“PDOException”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10085039/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PostgreSql 'PDOException' with message 'could not find driver'
提问by Dipro Sen
pdo is working fine with mysql but with pgsql its giving error 'PDOException' with message 'could not find driver'I've installed php5-pgsqlpackage which also includes pdo_pgsql
pdo 与 mysql 一起工作正常,但使用 pgsql 时出现错误'PDOException' with message 'could not find driver'我已经安装了php5-pgsql包,其中还包括pdo_pgsql
http://packages.debian.org/sid/php5-pgsql
http://packages.debian.org/sid/php5-pgsql
This package provides a module for PostgreSQL database connections directly from PHP scripts. It also includes the pdo_pgsql module for use with the PHP Data Object extension.
这个包提供了一个直接从 PHP 脚本连接 PostgreSQL 数据库的模块。它还包括用于 PHP 数据对象扩展的 pdo_pgsql 模块。
my dsn is pgsql:dbname=DB;host=192.168.0.2I am using Ubuntu 10.04
我的 dsn 是pgsql:dbname=DB;host=192.168.0.2我使用的是 Ubuntu 10.04
回答by Goms
This message means you need to installand or activatepostgresql extension in PHP
此消息意味着您需要在 PHP 中安装和/或激活postgresql 扩展
This solution works for me : To install postgresqlextension
此解决方案适用于我: 安装 postgresql扩展
[sudo] apt-get install php-pgsql
after, for activating it, uncomment pgsqland pdo-pgsqlextensions in etc/php/$PHP_VERSION/apache2/php.inifile
之后,为了激活它,取消文件中的注释pgsql和pdo-pgsql扩展名etc/php/$PHP_VERSION/apache2/php.ini
Finally, type :
最后,输入:
[sudo] /etc/init.d/apache2 restart
To restart apache server if you use apache such as was my case...
如果您使用 apache 重新启动 apache 服务器,例如我的情况...
回答by Jan Marek
1) Have you enabled pgsql.so in php.ini(extension=pgsql.so)?
1) 您是否在php.ini( extension=pgsql.so) 中启用了 pgsql.so ?
2) Is you Postgresql listenin on 192.168.0.2interface? (You can check it by netstat -tpln)
2) 你是否在192.168.0.2接口上监听 Postgresql ?(您可以通过netstat -tpln)
3) How you authenticate your access into Postgresql?
3) 如何验证您对 Postgresql 的访问?
回答by newenglander
Make sure you've uncommented the line that tells php where the Postgres driver is (usually extension=pgsql.so) in the main php.inifile.
确保您已取消注释告诉 php Postgres 驱动程序extension=pgsql.so在主php.ini文件中的位置(通常)的行。
回答by Maxim Klakov
I had the same issue. First of all - check is it enabled in php.ini. Uncomment extension=php_pdo_pgsql...
我遇到过同样的问题。首先 - 检查它是否在 php.ini 中启用。取消注释extension=php_pdo_pgsql...
than set up extension directory!!
比设置扩展目录!
extension_dir = "ext" ; for your case it could be other dir.
and do not forget to restart server after changing the config.
并且不要忘记在更改配置后重新启动服务器。
回答by Rafael Matsumoto
回答by Braian Coronel
When you do not have postgresql installed on the same machine that is Apache and PHP; you have to install php-pgsqland don't have to add extensionsin php.inimanually in Linux (in Windows yes), because redundancies are generated and this does not work (checked in error.log).
当您没有在 Apache 和 PHP 的同一台机器上安装 postgresql 时;您必须安装php-pgsql并且不必php.ini在 Linux中手动添加扩展(在 Windows 中是),因为会生成冗余并且这不起作用(已签入error.log)。
$ sudo apt install php-pgsql
Then you can check the existence of the extension enabled automatically in:
然后您可以检查是否存在自动启用的扩展:
$ sudo nano /etc/php/7.0/apache2/conf.d/10-pdo.ini
Observations: In phpinfo()you will find the directory conf.d/and the file error.log
观察:在phpinfo()您将找到目录conf.d/和文件error.log
GL
GL
回答by Amir Md Amiruzzaman
Here is what I did to solve the problem.
这是我为解决问题所做的工作。
Edit
php.iniand remove;fromextension=pdo_pgsql. Also, addextension=pgsql.soto thephp.inifile.Make sure to restart the Apache server before you try to see the result.
编辑
php.ini并;从extension=pdo_pgsql. 另外,添加extension=pgsql.so到php.ini文件中。在尝试查看结果之前,请确保重新启动 Apache 服务器。
回答by Gabriel Kniznik
Copy libpq.dll from the PHP directory to Apache24\bin(or wherever your installation could be).
将 libpq.dll 从 PHP 目录复制到 Apache24\bin(或您的安装位置)。


