PHP pdo异常“找不到驱动程序” pgSQL的 [英] PHP pdo exception "could not find driver" pgsql

查看:212
本文介绍了PHP pdo异常“找不到驱动程序” pgSQL的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我总是得到一个pdo异常,当我尝试在我的Mapper类的构造函数中创建我的数据库。
在这一行:

So i always get a pdo exception when i try to create my db in the constructor of my Mapper class. on this line:

$this->db = new PDO($dsn, $db_config['username'], $db_config['password']);

这是我的dsn创作:

    $db_config = array(
    'driver' => 'pgsql',
    'username' => $dbUser,
    'password' => $dbPassword,
    'schema' => 'r0628740',
    'dsn' => array(
        'host' => 'gegevensbanken.khleuven.be',
        'dbname' => '2TX31',
        'port' => '51314',
    )
);

并完成我的构造函数:

public function __construct(){
        global $db_config;
        $dsn = $db_config['driver'] . ':';
        foreach($db_config['dsn'] as $key => $value){
            $dsn .= $key . '=' . $value . ';';
        }
        try{

            $this->db = new PDO($dsn, $db_config['username'], $db_config['password']);
            $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

            if(($db_config['driver'] == 'pgsql') && isset($db_config['schema'])){
                $this->db->query(sprintf("SET SEARCH_PATH TO %s"), $db_config['schema']);
            }
        }catch (PDOException $e){
            var_dump($e->getLine());
            error_log($e->getMessage());
        }

    }


推荐答案

PHP包含pgsql和pgsql_pdo驱动程序libpq.dll所需的dll ...
将PHP二进制路径添加到系统路径或将其拷贝到Windows \system32中。 linux依赖关系是自动安装的。

The PHP contains a dll required by pgsql and pgsql_pdo driver libpq.dll... Add PHP binary path to system path or copy de DLL into Windows\system32. On linux dependency are installed automatically.

这篇关于PHP pdo异常“找不到驱动程序” pgSQL的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆