views:

385

answers:

1

I'm trying to use an Acces (MDB) database from a CakePHP app. On a Windows machine this works fine. On a Linux machine using Unixodbc this doesn't work at all. The error is as follows:

Warning (2): odbc_connect() [function.odbc-connect]: SQL error: [unixODBC][Driver anager]Data ource name not found, and no default driver specified, SQL state IM002 in SQLConnect [APP/vendors/adodb/drivers/adodb-odbc.inc.php, line 60]

The CakePHP datasource definition is:

             $default = array(
                            'driver' => 'adodb',
                            'connect'  => 'access',
                            'host' => "Driver=[MDBODBC]; Dbq=".$filePath.";Uid=Admin;Pwd=;}",
                            'login'    => 'Admin',
                            'password' => '',
                            'database' => ''
                    );

What's wrong with this configuration?

+1  A: 

The 'host' element looks odd in general because of its unmatched closing brace.

How does the line number 60 (from the error message) look in dodb-odbc.inc.php? Which elements of the configuration array does it use for the call to odbc_connect? Compare the call to the examples for the odbc_connect documentation.

Have you tried connecting using odbc_connect directly?

As an aside, my version of cake has an ODBC DBO driver actually within the cake framework, at

cake/libs/model/dbo/dbo_odbc.php

It uses odbc_pconnect. There, the $dsn string that is the first argument to odbc_pconnect comes from the 'database' element of the config array, not the 'host' element.

I don't know why you would use a third party solution in

app/vendors/adodb/drivers/adodb-odbc.inc.php

especially since the Date Library in John Lim ADOdb Library for PHP allows remote attackers to obtain sensitive information.

Ewan Todd