简体   繁体   English

PHP PDO ODBC 连接

[英]PHP PDO ODBC connection

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.我们希望有人可以帮助我们解决这个问题。

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')));
}

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

Possibly extension folder is located in the wrong place可能扩展文件夹位于错误的位置

open php.ini file and check "extension_dir"打开 php.ini 文件并检查“extension_dir”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM