This article mainly introduces the PHP Database link class (PDO + Access). If you need it, please refer to the php pdo Access link.
The code is as follows:
Class DbHelpClass
{
Private $ conn;
Private $ qxId;
Private $ ret;
Function _ construct ()
{
$ Path = ".../../App_Data/sd # f # 45G _!. Mdb ";
$ Constr = "DRIVER = {Microsoft Access Driver (*. mdb)}; DBQ =". realpath ($ path );
$ This-> conn = new PDO ("odbc: $ constr") or die ("PDO Connection faild .");
}
/* Read */
Function Read ($ SQL, $ params = array ())
{
$ Bind = $ this-> conn-> prepare ($ SQL );
$ ArrKeys = array_keys ($ params );
Foreach ($ arrKeys as $ row)
{
$ Bind-> bindValue (":". $ row, $ params [$ row]);
}
$ Bind-> execute () or die ('SQL error:'. $ SQL );
$ Result = $ bind-> fetchAll ();
Return $ result;
}
/* Add. you need to call this method for modification */
Function Edit ($ SQL, $ params = array ())
{
$ Bind = $ this-> conn-> prepare ($ SQL );
$ ArrKeys = array_keys ($ params );
Foreach ($ arrKeys as $ row)
{
$ Bind-> bindValue (":". $ row, $ params [$ row]);
}
$ A = $ bind-> execute () or die ('SQL error ');
Return $;
}
}
$ Dbh = new DbHelpClass ();