問題描述
我們正在嘗試通過 PHP 中的 ODBC 創(chuàng)建與 SQL 數(shù)據(jù)庫的連接.
we are trying to create a connection with our SQL database trough ODBC in PHP.
這是我們當(dāng)前的腳本:
$cnx = new PDO("odbc:Driver={EFR};Server=localhost;Port:7004;Database=EFR;Uid=LcLfVJFLTKTCEHRO;Pwd=*********;");
驅(qū)動(dòng)程序在 Qlikview 中工作,該 Qlikview 也連接到此數(shù)據(jù)庫.
The driver is working in Qlikview which also connects to this database.
驅(qū)動(dòng)確實(shí)被PHP發(fā)現(xiàn)了,但我們認(rèn)為它只是無法登錄.
The driver is actually being found by PHP, but we think it just can't login.
PHP 返回以下錯(cuò)誤:
PHP is returning the following error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[IM001] SQLDriverConnect: 0 No transaction control system' in C:Program Files (x86)EasyPHP-12.1wwwindex.php:2
Stack trace:
#0 C:Program Files (x86)EasyPHP-12.1wwwindex.php(2): PDO->__construct('odbc:Driver={EF...')
#1 {main} thrown in C:Program Files (x86)EasyPHP-12.1wwwindex.php on line 2
我們希望有人能幫助我們解決這個(gè)問題.
We hope someone can help us out with this problem.
推薦答案
如果您已經(jīng)定義了 ODBC 并存儲(chǔ)了密碼,您只需使用
if you already have the ODBC defined and have a stored password, you can simply connect with
$conn = new PDO("odbc:DSN_NAME")
其中 DSN_NAME 是您的 ODBC 數(shù)據(jù)源的實(shí)際名稱,無論是 MySQL、SQL Server 還是 DB2.
where DSN_NAME is the actual name of your ODBC datasource, be it MySQL, SQL Server or DB2.
您可以通過以下方式測試您的連接:
You can test your connection with the following:
try{
$conn = new PDO ("odbc:DSN_NAME");
die(json_encode(array('outcome' => true)));
}
catch(PDOException $ex){
die(json_encode(array('outcome' => false, 'message' => 'Unable to connect')));
}
這篇關(guān)于PHP PDO ODBC 連接的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!