So I using access database(*mdb). This my code and success to connect:
$db[\'test\'][\'hostname\'] = \'Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\blabl
$db['second']['hostname'] = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:/wamp/www/ket_noi_access/test1.mdb";//C:\wamp\www\ket_noi_access
$db['second']['username'] = "ADODB.Connection";
$db['second']['password'] = "xxxxx";
$db['second']['database'] = "C:/wamp/www/ket_noi_access/test1.mdb";
$db['second']['dbdriver'] = "odbc";
$db['second']['dbprefix'] = "";
$db['second']['pconnect'] = TRUE;
$db['second']['db_debug'] = TRUE;
$db['second']['cache_on'] = FALSE;
$db['second']['cachedir'] = "";
$db['second']['char_set'] = "utf8";
$db['second']['dbcollat'] = "utf8_general_ci";
$db['second']['swap_pre'] = '';
$db['second']['autoinit'] = TRUE;
$db['second']['stricton'] = FALSE;
code
function __construct(){
parent::__construct();
$this->legacy_db = $this->load->database('second',true);
}
function LayDanhSach(){
$this->legacy_db->select('*');
$this->legacy_db->from('ban');
$query = $this->legacy_db->get();
$kq=$query->result();
$this->legacy_db->close();
//$this->db->close();
return $kq;
}
$this->load->model("ban_model");
$ds=$this->ban_model->LayDanhSach();
$st="This is demo multi database and msaccess connect <br>";
$st.=json_encode($ds);
$this->data['content']=$st;//json_encode($ds);//echo json_encode($ds);
$this->load->view('index_view2',$this->data,false);
The problem is that the default IIS IUSER cannot access files over a network share. the workaround is detailed here: http://support.microsoft.com/kb/207671.
I would highly recommend using SQL Server (Express Edition if nothing else) than an access file - you will get a much improved experience + you will be able to migrate easier as the site expands if needed.
I found this thread for a similar problem: http://ellislab.com/forums/viewthread/93160/. Says you should try loading loading the odbc driver manually from your controller:
$this->load->database();
$this->db->dbdriver = “odbc”;
It also says that for some reason the database config is not available in the odbc driver:
system/database/drivers/odbc/odbc_driver.php
So you may also have to go in there and load the database config manually.
After many searches (nothing from the mentioned solution worked) I found a different solution, on some ms Access db's you can only connect using double slashes in the connection string (not in the database path):
$db['test']['hostname'] = 'Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\path\\to\my.mdb';
$db['test']['username'] = '';
$db['test']['password'] = '';
$db['test']['database'] = 'Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\path\to\my.mdb';
$db['test']['dbdriver'] = 'odbc';
$db['test']['dbprefix'] = '';
$db['test']['pconnect'] = TRUE;
$db['test']['db_debug'] = TRUE;
$db['test']['cache_on'] = FALSE;
$db['test']['cachedir'] = '';
$db['test']['char_set'] = 'utf8';
$db['test']['dbcollat'] = 'utf8_general_ci';
$db['test']['swap_pre'] = '';
$db['test']['autoinit'] = TRUE;
$db['test']['stricton'] = FALSE;
not sure what is the cause because I was able to connect on some Access db's (same server, same folder, same Access version) using single slashes and double slashes didn't work, think it's a silly joke of the same guy who worked on IE :-(
Check what user your PHP program is running under. List a directory content with PHP to check. Consider that user running your PHP can also has no mapping of Z
you made under you own username.
Have you checked read/write access to that file? If your php app is running on IIS, then your IIS' user account will need to have read/write permissions to that file, not the user account you use to login to your computer.