无法连接PostgreSQL与Yii

x759pob2  于 2022-11-09  发布在  PostgreSQL
关注(0)|答案(5)|浏览(123)

我已经尝试连接PostgreSQL与Yii,但它是显示
CDbConnection无法打开数据库连接。
在日志中显示

error   exception.CDbException

找不到驱动程序
我的代码

'db'=>array(
    'tablePrefix'=>'',
    'connectionString' => 'pgsql:host=localhost;port=5432;dbname=postgres',
    'username'=>'postgres',
    'password'=>'postgres',
    'charset'=>'UTF8',
),
wgx48brx

wgx48brx1#

Yii数据库组件是建立在PHP PDO之上的。所以这里有一些可能性需要检查
检查PostgreSQL和PostgreSQL的PDO扩展是否已安装并工作。端口是否正确。您可以测试简单的PHP脚本来测试。
以下是指向可能类似内容的链接
PostgreSql 'PDOException' with message 'could not find driver'
PDOException “could not find driver”

在Linux上安装PDO(Ubuntu/Debian)

Install pdo for postgres Ubuntu
https://serverfault.com/questions/89970/how-to-install-postgresql-extension-for-pdo-in-linux

视窗

http://blog.lysender.com/2010/08/php-and-postgresql-on-windows/
Apache php 5.3 postgreSQL driver could not be loaded

有关问题的官方PHP信息

http://php.net/manual/en/pdo.installation.php
http://www.php.net/manual/en/ref.pdo-pgsql.php

gopyfrb3

gopyfrb32#

已解决问题...通过添加

LoadFile "C:/wamp/bin/php/php5.3.5/libpq.dll"

到httpd.conf文件。现在phpinfo()正在显示pgsql PDO。
谢谢你...

mpbci0fu

mpbci0fu3#

如果你使用ubuntu,请确保你已经安装了pgsql库

sudo apt-get install php-pgsql
sudo service apache2 restart

确保控制台和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',
    ],],
wztqucjr

wztqucjr4#

在我的例子中,是在WAMP中启用php_pdo_pgsql扩展的例子

06odsfpq

06odsfpq5#

环境Yii 2服务器:LAMP stack 7.1问题驱动程序找不到,即“requirements.php”显示警告“PDO PostgreSQL extension Warning All DB-related classes Required for PostgreSQL database.”我注意到pdo_pgsql. so没有和bitnami一起打包,所以我在网上搜索它,或者尝试定位是否安装在/usr/lib/php中的任何php版本上
1.将文件复制到lampstack-7.1.10-1/php/lib/php/extensions中。
1.现在转到灯堆栈php.ini“灯堆栈-7.1.10-1/php/etc/php.ini”现在将这行“extension= pdo_pgsql. so”删除;如果注解掉NB,您可以指向绝对路径“/usr/lib/php/pdo_pgsql.so”(如果存在)
1.重新启动Lamp Apache服务器
1.访问requirement.php,如果看到“PDO PostgreSQL扩展已通过PostgreSQL数据库所需的所有与数据库相关的类"。

相关问题