I'm attempting to read from an Access database using MDBTools drivers to execute an odbc_connect
on Ubuntu 11.10. It's working fine when using the DSN setup in /etc/odbc.ini
.
Below are the contents of /etc/odbc.ini
:
[logindb]
Description = Microsoft Access Try DB
Driver = MDBToolsODBC
Database = /home/folder1/TestDb.mdb
Servername = localhost
The Driver attribute in odbc.ini
references MDBToolsODBC
, so, here is my odbc setup in /etc/odbcinst.ini
:
[MDBToolsODBC]
Description = MDB Tools ODBC
Driver = /usr/lib/libmdbodbc.so.0
Setup =
FileUsage =
CPTimeout =
CPReuse =
My problem is, when using $conn = odbc_connect('logindb','','');
, I have to use the hardcoded value for the database location. Ideally, I would like to specify the first parameter of odbc_connect
using a DSN-less connection, so that my database file can be a variable (will be reading from different dbs). Something like:
if ($cond1) {
$db = "/home/folder1/TestDb.mdb";
} else {
$db = "/home/folder1/TestDb2.mdb";
}
$conn = odbc_connect("odbc:Driver={MDBToolsODBC};Dbq=$db",'','');
I've also tried it without the odbc: prefix, but it did not work. Can anyone tell me why specifying the DSN works, but when trying to specify it on the fly using what looks like the same attributes, it doesn't work? I'm thinking it has to do with the parameters and contents of the first parameter in the DSN-less connection. As always, any help is greatly appreciated.
/etc/odbc.ini
, shouldn't it beDatabase=$db
? – MorezSQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified
. – NotedDriver=/usr/lib/libmdbodbc.so.0
? – Morez$conn = odbc_connect('logindb','','');
works fine. – Notedodbc_connect("Driver=/usr/lib/libmdbodbc.so.0;Database=$db",'','')
? – Morez$conn = odbc_connect("odbc:Driver={MDBToolsODBC};Dbq=".$db,'','');
work? (concatenating the string)? – Chord