Convert MDB File to MySQL: If you are looking to store your Microsoft Access Database file data in your server database, so this tutorial for you. I was looking for many sites to get the appropriate answer. I could not found the proper answer. I have got success to save MDB data in my MySQL database table, which I will share with you in this tutorial. If you are using the PHP Codeigniter framework it will more helpful for you. You can easily convert all table data which have in the MDB file to the MySQL database.
First, create all table structures in the MySQL database. I have created a table, you can follow it.
`id` int(11) NOT NULL,
`name` text,
`username` varchar(100) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
`status` int(1) DEFAULT NULL COMMENT ‘1=Active, 0=Inactive, 2=Remove’,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `users`
ADD PRIMARY KEY (`id`);
—
— AUTO_INCREMENT for dumped tables
—
—
— AUTO_INCREMENT for table `users`
—
ALTER TABLE `users`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;
COMMIT;
Now place your .mdb file in a project folder. I have created a folder under the application folder and give the folder name database and put my .mdb file into the database folder. My path location like this:
https://www.example.com/myProject/application/database/allTableData.mdb
Create a route.
Route:
After creating the route you have to create a controller file like DatabaseSyncController.
Controller:
defined(‘BASEPATH’) OR exit(‘No direct script access allowed’);
class DatabaseSyncController extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper(‘url’);
$this->load->library(array(‘session’));
$this->load->model(array(‘Users’));
}
public function index() {
$cDate = date(‘Y-m-d H:i:s’);
$dbname = APPPATH.’database/allTableData.mdb’;
$access[‘hostname’] = “DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=”.$dbname;
$access [“username”] = “”;
$access [“password”] = “”;
$access [“database”] = $dbname;
$access [“dbdriver”] = “odbc”;
$access [“dbprefix”] = “”;
$access [“pconnect”] = FALSE;
$access [“db_debug”] = false;
$access [“cache_on”] = FALSE;
$access [“cachedir”] = “”;
$access [“char_set”] = “utf8”;
$access [“dbcollat”] = “utf8_general_ci”;
$access [“swap_pre”] = ”;
$access [“autoinit”] = TRUE;
$access [“stricton”] = FALSE;
$access_db = $this->load->database($access, true);
$MDBUserData = $access_db->query(“SELECT * FROM MDBusers”);
if($MDBUserData->num_rows() > 0) {
$flag = 0;
foreach ($MDBUserData->result() as $row) {
$arrayData = array(‘name’ => $row->MDBname, ‘username’ => $row->MDBusername, ‘password’ => $row->MDBassword’status’ => “1”, ‘created_at’ => $cDate, ‘updated_at’ => $cDate);
$this->Users->insert($arrayData);
$flag++;
}
if($flag == $MDBUserData->num_rows()) {
echo “<h1>User table record save done!</h1>\n”;
}
}
}
}
?>
If you have any problem to do it, you can comment here.
Hello I am using ms access database but I am getting error could u help me please
Sure