PHP uses the Accessmdb connector PHP to Access the Access information provided by ODBC.
Logging environment ODBC for Access MDB settings:
1. Windows
On windows, run php_pdo_odbc.dll extension in php. ini.
extension=php_pdo_odbc.dll
2. Linux
In Linux, you must install ODBC and mdbtools separately.
[Mdbtools description]
Mdbtools is the solution for operating the Access MDB free-of-charge solution on Linux,
However, in my temporary version, only the SQL statement method that can be used to write a single statement can be used. some SQL statements are normal on windows,
However, in linux, all mdbtools cannot be used to parse the line (false after the php pdo operation, the Couldn't parse SQL crash occurs after the ODBC operation is directly used ).
Installing php-odbc
$ yum install php-odbc
Installing MDBTools
$ yum install mdbtools
Install mdbtools-devel and install libmdbodbc. so.
$ yum install mdbtools-devel
View the content in/etc/odbcinst. ini and check the preset format.
$ less /etc/odbcinst.ini# Example driver definitions# Driver from the postgresql-odbc package# Setup from the unixODBC package[PostgreSQL]Description = ODBC for PostgreSQLDriver = /usr/lib/psqlodbcw.soSetup = /usr/lib/libodbcpsqlS.soDriver64 = /usr/lib64/psqlodbcw.soSetup64 = /usr/lib64/libodbcpsqlS.soFileUsage = 1# Driver from the mysql-connector-odbc package# Setup from the unixODBC package[MySQL]Description = ODBC for MySQLDriver = /usr/lib/libmyodbc5.soSetup = /usr/lib/libodbcmyS.soDriver64 = /usr/lib64/libmyodbc5.soSetup64 = /usr/lib64/libodbcmyS.soFileUsage = 1
We can see that if ODBC for MDB is required, the lib and lib64 contents should have an issue similar to libmdbodbc. so.
$ Ls-al/usr/lib/libmdb * ls: you cannot access/usr/lib/libmdb *: there is no such case or the project $ ls-al/usr/lib64/libmdb *-rwxr-xr-x 1 root 38240 February 20 2015/usr/lib64/libmdbodbc. so-rwxr-xr-x 1 root 42536 February 20 2015/usr/lib64/libmdbodbcW. solrwxrwxrwx 1 root 15 February 5 17:14/usr/lib64/libmdb. so-> libmdb. so.2.0.1lrwxrwxrwx 1 root 15 February 5 16:35/usr/lib64/libmdb. so.2-> libmdb. so.2.0.1-rwxr-xr-x 1 root 90104 February 20 2015/usr/lib64/libmdb. so.2.0.1lrwxrwxrwx 1 root 18 February 5 17:14/usr/lib64/libmdbsql. so-> libmdbsql. so.2.0.0lrwxrwxrwx 1 root 18 February 5 16:35/usr/lib64/libmdbsql. so.2-> libmdbsql. so.2.0.0-rwxr-xr-x 1 root 41144 February 20 2015/usr/lib64/libmdbsql. so.2.0.0
It can be found that there is a protocol link for libmdbodbc. so under usr/lib64 /.
In odbcinst. ini, add an MDBTools mdb odbc Driver (the name can be customized ).
$ vi /etc/odbcinst.ini[MyMDBDriver]Description = MDBTools MDB ODBC DriverDriver = /usr/lib/libmdbodbc.soSetup = /usr/lib/libmdbodbc.soDriver64 = /usr/lib64/libmdbodbc.soSetup64 = /usr/lib64/libmdbodbc.soFileUsage = 1UsageCount = 1
Example of a PHP program:
$ Uname = explode ("", php_uname (); $ OS = $ uname [0]; switch ($ OS) {case 'windows': $ mdb_file = 'd: \ test. mdb '; $ driver =' {Microsoft Access Driver (*. mdb)} '; break; case 'Linux': $ mdb_file = '/home/test. mdb '; $ driver = 'mydbdriver'; // in/etc/odbcinst. the configuration name in ini is reset break; default: exit ("Don't know about this OS");} $ export cename = "odbc: Driver = $ driver; DBQ = $ mdb_file; "; $ connection = new PDO ($ dataSourceName); $ SQL =" SELECT * FROM test "; $ stmt = $ connection-> query ($ SQL ); $ data = $ stmt-> fetchAll (\ PDO: FETCH_ASSOC );
Exam:
Access a mdb database from a php web site
How to handle MS Access MDB files in Linux with PHP5 PDO and ODBC GitHub
PHP: PDO_ODBC DSN-Manual
Others:
1. add the following settings in/etc/odbc. ini:
$ vi /etc/odbc.ini[MDBtest]Description = The Source of My test mdbDriver = MyMDBDriverServerName = localhostDatabase = /home/test.mdb
In this way, you can enter the SQL command interface. after entering the interface, you can directly use the SQL command to operate the/home/test. mdb data volume.
$ isql -v MDBtest+---------------------------------------+| Connected! || || sql-statement || help [tablename] || quit || |+---------------------------------------+SQL>
2. zookeeper security protection mdbtools:
GitHub-brianb/mdbtools: MDB Tools-Read Access databases on * nix
Install mdbtools on Centos 7-Dale Scott
tar zxvf mdbtools-0.6pre1.tar.gzcd mdbtools-0.6pre1/autoreconf -i -f./configure --with-unixodbc=/usr/localmakemake install
3. Access mdb time slot:
In SQL statement, the condition value contains a value in the date format, which must be added around the date value #
$sql = "SELECT * FROM test WHERE aa >#{2016-03-15}#";
Exam: What is the difference between the SQL statement of mdf and mdb? -Delphi K. Top Forum