問題描述
我們正在嘗試通過 PHP 中的 ODBC 創建與 SQL 數據庫的連接.
we are trying to create a connection with our SQL database trough ODBC in PHP.
這是我們當前的腳本:
$cnx = new PDO("odbc:Driver={EFR};Server=localhost;Port:7004;Database=EFR;Uid=LcLfVJFLTKTCEHRO;Pwd=*********;");
驅動程序在 Qlikview 中工作,該 Qlikview 也連接到此數據庫.
The driver is working in Qlikview which also connects to this database.
驅動確實被PHP發現了,但我們認為它只是無法登錄.
The driver is actually being found by PHP, but we think it just can't login.
PHP 返回以下錯誤:
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
我們希望有人能幫助我們解決這個問題.
We hope someone can help us out with this problem.
推薦答案
如果您已經定義了 ODBC 并存儲了密碼,您只需使用
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 數據源的實際名稱,無論是 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')));
}
這篇關于PHP PDO ODBC 連接的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!