Home > Article > Backend Development > pdo connection access database code_PHP tutorial
pdo connection access database tutorial code
//php tutorial.ini needs to be opened:
//extension=php_pdo.dll
//extension=php_pdo_odbc.dll
//The database is acc.mdb, to prevent malicious downloads, change it to acc.php
try{
$db = new pdo("odbc:driver={microsoft access driver (*.mdb)};dbq=".getcwd()."acc.php",'aaa','123456'); //getcwd() The function is to get the current path
//echo "connectedn";
date_default_timezone_set('asia/shanghai'); //Beijing time
$v="Test".date("y-m-d h:i:s")."Added content";
$db->exec("insert into table1(topic) values('$v')");//Insert
//echo $db->lastinsertid(); //Not supported
$rs=$db->query("select * from table1"); //Select
while($row=$rs->fetch()){
echo $row[id]."-".$row[topic]."
";
};
} catch (exception $e) {
//echo "failed:".$e->getmessage();
}