PHP DBlib PDO问题

我试图通过
PHP连接到MSSQL服务器,但我的pdo连接给了我一个困难的时间和错误,我真的不明白.我下面粘贴的代码在一周前工作得很好,突然间它就停止了,没有任何人改变任何东西.我仍然可以连接到服务器并直接从命令行运行查询,但我在php中没有相同的运气.

有人看到我遗失的东西吗?我已经花了太多时间在这上面,似乎我在圈子里跑.

首先,这是我从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

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

最佳答案 我们从使用dblib更改为odbc,我的类中的代码更改为:

 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());
        }
点赞