How to read MS Access backup .mdb files using PHP?
Recently I have has a challenging experience with integrating MS Access backup files (.mdb format) into my own MySQL database. That was part of small web application for integrating MS Access with cloud services.
After a couple of failed attempts to parse to .mdb file using pure PHP I had to conclude that this is not stable solution..
An alternative option I found is to use utility “mdb-tools”, which has a bunch of CLI commands for parsing .mdb files.
So, using PHP function shell_exec() I did a trick and solved the problem.
If you still don’t sleep, then you probably interested why am I telling this boring story?… :D
To know this read the rest ;)
After I solved this tricky challenge, I come up with an idea to create composer package and simplify life of other developers..
You can install this package like this:
composer require mdb-tools/mdb-parser
Also you need to install “mdb-tools”:
apt-get update -y
apt-get install -y mdbtools
In your code, with this package you can do things like this:
use MDBTools\Facades\Parsers\MDBParser;
$parser = MDBParser::loadFile(‘/path/to/file’);
//see table names…
$tables = $parser->tables();
Above code will fetch list of tables.
If you need to parse some table you can do like this:
//parse data from one chosen table...
print_r($parser->selectTable('some_table')->toArray());
Links:
I like to talk, so please contact via my linkedin: https://www.linkedin.com/in/oleksii-fedorchak-web-developer/
You may find more about this package here:
1) Documentation: https://mdb-parcer.tech/
2) Github: https://github.com/OleksiiFedorchak/mdb-tools
3) Packgist: https://packagist.org/packages/mdb-tools/mdb-parser