如何向CodeIgniter或CakePHP添加MSAccess连接? [英] How do I add an MSAccess connection to CodeIgniter or CakePHP?
问题描述
我试图使用Microsoft Access数据库的一个演示项目,我想在CodeIgniter或CakePHP。忽略使用Microsoft Access的可能愚蠢,我还没有能够精确地确定连接字符串对应于框架的数据库设置。在直接PHP中,我可以使用此代码连接到Access数据库:
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"
);
这些字符串如何对应于代码Igniter数据库设置?这似乎不太工作:
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";
推荐答案
尝试设置DSN并更改为:
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>";
CodeIgniter文档中还有一个用于解决连接字符串的部分:
There's also a section in the CodeIgniter documentation that addresses connection strings:
http://codeigniter.com/user_guide/database/connecting.html
这篇关于如何向CodeIgniter或CakePHP添加MSAccess连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!