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