PHP PDO ODBC连接 [英] PHP PDO ODBC connection
问题描述
我们正在尝试通过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中运行,该驱动程序也连接到该数据库.
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.1\www\index.php:2
Stack trace:
#0 C:\Program Files (x86)\EasyPHP-12.1\www\index.php(2): PDO->__construct('odbc:Driver={EF...')
#1 {main} thrown in C:\Program Files (x86)\EasyPHP-12.1\www\index.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连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!