无法将 PostgreSQL 与 Yii 连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13136285/
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
Not able to connect PostgreSQL with Yii
提问by rajmohan
I have tried to connect PostgreSQL with Yii but is is showing
我曾尝试将 PostgreSQL 与 Yii 连接,但正在显示
CDbConnection failed to open the DB connection.
CDbConnection 未能打开数据库连接。
In log it is showing
在日志中它显示
error exception.CDbException
could not find driver
找不到驱动程序
My code
我的代码
'db'=>array(
'tablePrefix'=>'',
'connectionString' => 'pgsql:host=localhost;port=5432;dbname=postgres',
'username'=>'postgres',
'password'=>'postgres',
'charset'=>'UTF8',
),
回答by Stefano Mtangoo
Yii Database component is build on top of PHP PDO. So Here are list of posibilities to check
Yii 数据库组件建立在 PHP PDO 之上。所以这里是检查的可能性列表
Check that PostgreSQL and PostgreSQL's PDO Extension is installed and working. Also that port is right one. You can test simple PHP Script to test.
检查 PostgreSQL 和 PostgreSQL 的 PDO 扩展是否已安装并正常工作。那个端口也是正确的。您可以测试简单的PHP 脚本来测试.
Below are links to something that might be similar
以下是指向可能类似内容的链接
PostgreSql 'PDOException' with message 'could not find driver'
带有消息“找不到驱动程序”的 PostgreSql“PDOException”
PDOException “could not find driver”
Install PDO on Linux (Ubuntu/Debian)
在 Linux (Ubuntu/Debian) 上安装 PDO
Install pdo for postgres Ubuntu
https://serverfault.com/questions/89970/how-to-install-postgresql-extension-for-pdo-in-linux
https://serverfault.com/questions/89970/how-to-install-postgresql-extension-for-pdo-in-linux
Windows
视窗
http://blog.lysender.com/2010/08/php-and-postgresql-on-windows/
http://blog.lysender.com/2010/08/php-and-postgresql-on-windows/
Apache php 5.3 postgreSQL driver could not be loaded
无法加载 Apache php 5.3 postgreSQL 驱动程序
Official PHP Information on Issue
有关问题的官方 PHP 信息
http://php.net/manual/en/pdo.installation.php
http://php.net/manual/en/pdo.installation.php
回答by rajmohan
Resolved issue...by adding
已解决问题...通过添加
LoadFile "C:/wamp/bin/php/php5.3.5/libpq.dll"
to httpd.conf file. Now phpinfo() is showing pgsql PDO.
到 httpd.conf 文件。现在 phpinfo() 显示 pgsql PDO。
thanks...
谢谢...
回答by Andrea Perdicchia
if you work in ubuntu make sure that you have installed pgsql library
如果您在 ubuntu 中工作,请确保您已安装 pgsql 库
sudo apt-get install php-pgsql
sudo service apache2 restart
after make sure that in the console and main-local there are this array
在确保在控制台和 main-local 中有这个数组之后
'components' => [
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'pgsql:host=localhost;port=5432;dbname=yourdb',
'username' => 'user',
'password' => 'pw',
'charset' => 'utf8',
],],
回答by iGbanam
In my case, it was a case of enabling the php_pdo_pgsql
extension in WAMP
就我而言,这是php_pdo_pgsql
在 WAMP中启用扩展的情况