PHP PDO ODBC 连接

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

问题描述

限时送ChatGPT账号..

我们正在尝试通过 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 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死锁异常代码?)
PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滚动游标不起作用)
Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔术方法)
php pdo get only one value from mysql; value that equals to variable(php pdo 只从 mysql 获取一个值;等于变量的值)
MSSQL PDO could not find driver(MSSQL PDO 找不到驱动程序)
PDO connection works from command line, but not through Apache?(PDO 连接从命令行工作,而不是通过 Apache?)