PHP DBlib PDO问题 [英] PHP DBlib PDO Issue

查看:97
本文介绍了PHP DBlib PDO问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过php连接到MSSQL服务器,但是我的pdo连接给我带来了困难和我不真正理解的错误.我在下面粘贴的代码一周前运行良好,突然之间,它停止了运行而没有任何更改.我仍然可以连接到服务器并直接从命令行运行查询,但是我在php中没有同样的运气. 有人看到我想念的东西吗?我已经花了太多时间在这上面,好像我在圈子里奔跑.

I am trying to connect to an MSSQL server through php but my pdo connection is giving me a hard time and errors that I don't really understand. The code I pasted below was working just fine a week ago and all of a sudden it just stopped without anyone changing anything. I can still connect to the server and run queries directly from the command line but I'm not having the same luck within php. Anyone see something that I am missing? I spent too much time on this already and it seems like I'm running in circles.

首先,这是我从PDOException中得到的错误

SQLSTATE[] (null) (severity 0)

我的Mssql()的一部分

 private function __construct() {
        try{
           $this->_pdo = new PDO('dblib:host=' . Config::get('prod/host') . ':'. Config::get('prod/port') .';dbname=' . Config::get('prod/db'),Config::get('prod/username'), Config::get('prod/password'));
        }catch(PDOException $e){
            die($e->getMessage());
        }
    }

    public static function getInstance(){
        // Already an instance of this? Return, if not, create.
        if (!isset(self::$instance)) {
            self::$instance = new Mssql();
        }
        return self::$instance;
    } //...This function is working and directs to __construct()

我怎么称呼

/*Some random php file*/
function getClients(){
    $conn = Mssql::getInstance();
//.....

还有我的init.php

And my init.php

//...
prod' => array(
        'host'      => 'xxxxxxx',
        'port'      => '1433',
        'username'  => 'xxxxxxx',
        'password'  => 'xxxxxx',
        'db'        => 'xxxxxxx'
    ),
//.....

推荐答案

我们从使用dblib更改为odbc,并将我班级中的代码更改为:

We changed from using dblib to odbc and the code in my class changed to this:

 private function __construct() {
        putenv('ODBCSYSINI=/etc');
        putenv('ODBCINI=/etc/odbc.ini');
        $username = "xxxx";
        $password = "xxxx";
        try {
            $this->_pdo = new PDO("odbc:production","$username","$password");
        } catch (PDOException $exception) {                
            die($exception->getMessage());
        }

这篇关于PHP DBlib PDO问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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