Home  >  Article  >  Backend Development  >  Summary of how to connect Access database with PHP_PHP tutorial

Summary of how to connect Access database with PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:04:50868browse

PHP code:

It should be noted that php uses realpath to obtain the path

Copy code The code is as follows:

$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";
?>


Part 2:

Copy code The code is as follows:

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

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


Method 3: Use ODBC, in ODBC Create a system data source for db1.mdb in the manager (generally requires server permissions, not recommended)

Name: dbdsn (you can customize it yourself)
Driver: Microsoft Access Driver (*.MDB )

Code:
Copy code The code is as follows:

$Conn = odbc_connect("dbdsn", "admin","123"); //Connect to data source
$Doquery=odbc_exec($Conn,"select * from table name where condition");//Execute query


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327737.htmlTechArticlePHP code: Please note that php uses realpath to obtain the path. Copy the code as follows: ?php $connstr="DRIVER ={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("data.mdb"); $connid=odb...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn