PHP PDO ODBC连接 [英] PHP PDO ODBC connection

查看:468
本文介绍了PHP PDO ODBC连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试通过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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆