简体   繁体   English

PHP DBlib PDO问题

[英]PHP DBlib PDO Issue

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. 我试图通过PHP连接到MSSQL服务器,但我的pdo连接给了我一个困难的时间和错误,我真的不明白。 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. 我仍然可以连接到服务器并直接从命令行运行查询,但我在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. 我已经花了太多时间在这上面,似乎我在圈子里跑。

First, this is the error I am getting from my PDOException 首先,这是我从PDOException获得的错误

SQLSTATE[] (null) (severity 0)

Part of my Mssql() 我的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()

How I am calling it 我怎么称呼它

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

And my init.php 还有我的init.php

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

We changed from using dblib to odbc and the code in my class changed to this: 我们从使用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());
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM