沃梦达 / 编程问答 / php问题 / 正文

PHP PDO ODBC 连接

PHP PDO ODBC connection(PHP PDO ODBC 连接)

本文介绍了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 中工作,该 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 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:PHP PDO ODBC 连接

基础教程推荐