pdo連接access數據庫教程代碼
//php教程.ini需要開放:
//extension=php_pdo.dll
//extension=php_pdo_odbc.dll
//數據庫為acc.mdb,為防止惡意下載,改為acc.php
try{
$db = new pdo("odbc:driver={microsoft access driver (*.mdb)};dbq=".getcwd()."\acc.php",'aaa','123456'); //getcwd()函數是獲取當前路徑
//echo "connectedn";
date_default_timezone_set('asia/shanghai'); //北京時間
$v="測試".date("y-m-d h:i:s")."添加的內容";
$db->exec("insert into table1(topic) values('$v')");//插入
//echo $db->lastinsertid(); //不支持
$rs=$db->query("select * from table1"); //選擇
while($row=$rs->fetch()){
echo $row[id]."-".$row[topic]."<br>";
};
} catch (exception $e) {
//echo "failed:".$e->getmessage();
}