Question

I'm trying to use a Microsoft Access database for a demo project that I'm thinking of doing in either CodeIgniter or CakePHP. Ignoring the possible folly of using Microsoft Access, I haven't been able to figure out precisely how the connection string corresponds to the frameworks' database settings. In straight PHP, I can use this code to connect to an Access database:

$db_connection = odbc_connect(
  "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=\\path\\to\\db.mdb", 
  "ADODB.Connection", "", "SQL_CUR_USE_ODBC"
);

How do those strings correspond to the Code Igniter db settings? This doesn't seem to be quite working:

$db['access']['hostname'] = "{Microsoft Access Driver (*.mdb)}";
$db['access']['username'] = "ADODB.Connection";
$db['access']['password'] = "";
$db['access']['database'] = "\\path\\to\\db.mdb";
$db['access']['dbdriver'] = "odbc";
$db['access']['dbprefix'] = "";
$db['access']['pconnect'] = TRUE;
$db['access']['db_debug'] = TRUE;
$db['access']['cache_on'] = FALSE;
$db['access']['cachedir'] = "";
$db['access']['char_set'] = "utf8";
$db['access']['dbcollat'] = "utf8_general_ci";
Was it helpful?

Solution

Try setting up a DSN and changing to the following:

$db['access']['hostname'] = "<dsn name>";
$db['access']['username'] = "";
$db['access']['password'] = "";
$db['access']['database'] = "<dsn name>";

There's also a section in the CodeIgniter documentation that addresses connection strings:

http://codeigniter.com/user_guide/database/connecting.html

OTHER TIPS

Would it be possible to use the SQL Express (free!) engine instead and just import/export your MS Access db? You could thank me later on that. :-)

Another option is to use the ADOdb library instead of CI's native DB library, though you'll lose the Active Record support from CI, and have to rewrite certain libraries in CI to utilize it, but it's worth it if you still want to use CI with a DB that isn't supported for your application. I had to do it early on when there was bugs in the Postgres implementation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top