PHP代碼:
需要注意php獲取路徑用的是realpath
復制代碼 代碼如下:
<?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";
?>
之二:
復制代碼 代碼如下:
<?PHP
//創建ADO連接
$conn = @new COM("ADODB.Connection") or die ("ADO連接失敗!");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("temp/TempData.mdb");
$conn->Open($connstr);
//創建記錄集查詢
$rs = @new COM("ADODB.RecordSet");
$rs->Open("select * from blog_Content",$conn,1,3);
echo $rs->Fields["log_Title"]->Value; //輸出log_Title字段
echo "<br/>";
$rs->Movenext(); //將記錄集指針下移
echo $rs->Fields["log_Title"]->Value;
$rs->close();
?>
方法三:用ODBC,在ODBC治理器中為db1.mdb建一處系統數據源(一般需要服務器權限,不建議使用)
名稱:dbdsn (可以自己定)
驅動程序:Microsoft Access Driver (*.MDB)
代碼:
復制代碼 代碼如下:
$Conn = odbc_connect("dbdsn","admin","123"); //連接數據源
$Doquery=odbc_exec($Conn,"select * from 表名 where 條件");//執行查詢