Method summary of PHP connection to Access database

  • 2020-06-15 07:56:15
  • OfStack

PHP code:

Note that php USES realpath to get the path
 
<?php 
$connstr="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("data.mdb"); 
$connid=odbc_connect($connstr,"","",SQL_CUR_USE_ODBC); 
$issuetime=date("Y-m-d H:i:s"); 
$sql="insert into test values("","",...)"; 
$result=odbc_exec($connid,$sql); 
if($result) echo "successful"; 
else echo "failed"; 
?> 


2:

 
<?PHP 
// create ADO The connection  
$conn = @new COM("ADODB.Connection") or die ("ADO The connection fails !"); 
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("temp/TempData.mdb"); 
$conn->Open($connstr); 

// Create a recordset query  
$rs = @new COM("ADODB.RecordSet"); 
$rs->Open("select * from blog_Content",$conn,1,3); 
echo $rs->Fields["log_Title"]->Value; // The output log_Title field  
echo "<br/>"; 
$rs->Movenext(); // Move the recordset pointer down  
echo $rs->Fields["log_Title"]->Value; 
$rs->close(); 
?> 


Method 3: Use ODBC and set up a system data source for ES16en1.mdb in ODBC administrator (1 server permissions are generally required and not recommended)

Name :dbdsn (you can decide)
Driver :Microsoft Access Driver (*.MDB)

Code:
 
$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  



Related articles: