Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP PDO ODBC connection

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.

like image 630
user2248551 Avatar asked Apr 05 '13 10:04

user2248551


People also ask

What is PDO ODBC?

Introduction ¶ PDO_ODBC is a driver that implements the PHP Data Objects (PDO) interface to enable access from PHP to databases through ODBC drivers or through the IBM DB2 Call Level Interface (DB2 CLI) library. PDO_ODBC currently supports three different "flavours" of database drivers: ibm-db2.

What is PHP ODBC?

PHP is one of the most common open-source programming languages for web applications and websites development. ODBC is an API that allows you to connect to a data source, such as PostgreSQL, Oracle, MySQL, MongoDB or SQL Server, using standard PHP functions and Devart ODBC Drivers.

What is the purpose of ODBC?

Open Database Connectivity (ODBC) is an open standard application programming interface (API) that allows application programmers to access any database.


1 Answers

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')));
}
like image 133
user42405 Avatar answered Oct 20 '22 04:10

user42405