PHP database connection class (PDO + Access) instance
This article mainly introduces the PHP database connection class (PDO + Access). If you need it, please refer to it.
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 ();