PHP PDO ODBC connection
Asked Answered
C

3

5

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

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.

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

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.

Conduit answered 5/4, 2013 at 10:10 Comment(1)
Try this as your connection string: $cnx = new PDO("odbc:Driver={EFR};Server=localhost;Port:7004;Database=EFR", 'LcLfVJFLTKTCEHRO', '*********');Geelong
A
8

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

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

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')));
}
Aquiver answered 8/1, 2014 at 7:3 Comment(2)
Hi, what is DNS_NAME, can be the IP number?Pittman
Using the string "odbc:DNS_NAME" the result is {"outcome":false,"message":"Unable to connect"}Pittman
B
1

try adding DSN on System instead of user

Berdichev answered 2/11, 2017 at 11:24 Comment(0)
W
0

Possibly extension folder is located in the wrong place

open php.ini file and check "extension_dir"

Wrac answered 1/6, 2022 at 17:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.