Three php methods to connect to the access database

  • 2020-11-20 06:02:16
  • OfStack

One is to use pdo of php, the other is odbc,com interface to connect to the access database.
Use pdo to connect to the access database


$path ="f:fontwww.ofstack.comspiderresult.mdb"; 
 $conn = new pdo("sqlite:$path");
 if( $conn )
 {
  echo ('connection pdo success');
 }
 else
 {
  echo ('cnnection pdo fail ,plase check database server!');
 }

Connect to the database using odbc_connect

 $conn = odbc_connect("dbdsn","admin","123"); // Connect to data source  
 $doquery=odbc_exec($conn,"select * from  The name of the table  where  conditions ");// Execute the query  
 

Connect to the access database using the com interface
$conn=new com("adodb.connection");
$dsn="driver={microsoft access driver (*.mdb)};dbq=".realpath("path/db1.mdb");
$conn- > open($dsn);


Related articles: