PHP PDO ODBC 连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15831246/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 10:02:33  来源:igfitidea点击:

PHP PDO ODBC connection

phppdoodbcqlikview

提问by user2248551

we are trying to create a connection with our SQL database trough ODBC in PHP.

我们正在尝试通过 PHP 中的 ODBC 创建与我们的 SQL 数据库的连接。

This is our current script:

这是我们当前的脚本:

$cnx = new PDO("odbc:Driver={EFR};Server=localhost;Port:7004;Database=EFR;Uid=LcLfVJFLTKTCEHRO;Pwd=*********;"); 

The driver is working in Qlikview which also connects to this database.

驱动程序在 Qlikview 中工作,该 Qlikview 也连接到此数据库。

The driver is actually being found by PHP, but we think it just can't login.

该驱动程序实际上是由 PHP 找到的,但我们认为它只是无法登录。

PHP is returning the following error:

PHP 返回以下错误:

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.

我们希望有人可以帮助我们解决这个问题。

回答by user42405

if you already have the ODBC defined and have a stored password, you can simply connect with

如果您已经定义了 ODBC 并存储了密码,则可以简单地连接

$conn = new PDO("odbc:DSN_NAME") 

where DSN_NAME is the actual name of your ODBC datasource, be it MySQL, SQL Server or DB2.

其中 DSN_NAME 是 ODBC 数据源的实际名称,可以是 MySQL、SQL Server 或 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')));
}

回答by Serak Shiferaw

try adding DSN on System instead of user

尝试在系统而不是用户上添加 DSN