Home >Backend Development >PHP Tutorial >How to connect Access database with PHP_PHP tutorial
D:Accessdb1.mdb
Username: Admin
Password: 123
Please tell me how to establish a connection with this file in PHP
-------------------------------------------------- -------------
The first way is to use ODBC and create a system data source for db1.mdb in the ODBC manager
Name: dbdsn (you can decide it yourself)
Driver:Microsoft Access Driver (*.MDB)
Code:
...
$Conn = odbc_connect("dbdsn","admin","123"); //Connect to data source
$Doquery=odbc_exec($Conn,"select * from table name where condition");//Execute query
...
The second way is ADO
...
$conn=new COM("ADODB.Connection");
$dsn="DRIVER={Microsoft Access Driver (*.mdb)};DBQ=".realpath("path/db1.mdb");
$conn->open($dsn);
$sql="select * from table name where condition";
$ru=$conn->Execute($sql);