Recently, I received a website application of PHP + Access and perspiration. I have never used php + Access before. I have participated in some other functions by referring to the access functions written by others, encapsulated as a class, it is very convenient to call, although it has not been tested,
Recently, I received a website application called PHP Access and sweated. I have never used php Access before. refer to the access function written by others and I have participated in some other functions and encapsulated them into a class, I feel that the call is quite convenient. although I have never tested it, I feel that PHP Access is not as fast as PHP MySQL.
The code is as follows:
PHP code:
--------------------------------------------------------------------
// FileName: class. php
// Summary: Access database control class
// Application model:
// $ Databasepath = 'database. mdb ';
// $ Dbusername = '';
// $ Dbpassword = '';
// Include_once ('class. php ');
// $ Access = new Access ($ databasepath, $ dbusername, $ dbpassword );
--------------------------------------------------------------------
Class Access
{
Var $ databasepath, $ constr, $ dbusername, $ dbpassword, $ link;
Function Access ($ databasepath, $ dbusername, $ dbpassword)
{
$ This-> databasepath = $ databasepath;
$ This-> username = $ dbusername;
$ This-> password = $ dbpassword;
$ This-> connect ();
}
Function connect ()
{
$ This-> constr = 'driver = {Microsoft Access DRIVER (*. mdb)}; DBQ = '. realpath ($ this-> databasepath );
$ This-> link = odbc_connect ($ this-> constr, $ this-> username, $ this-> password, SQL _CUR_USE_ODBC );
Return $ this-> link;
// If ($ this-> link) echo 'congratulations, the database connection is successful! ';
// Else echo 'database connection failed! ';
}
Function query ($ SQL)
{
Return @ odbc_exec ($ this-> link, $ SQL );
}
Function first_array ($ SQL)
{
Return odbc_fetch_array ($ this-> query ($ SQL ));
}
Function fetch_row ($ query)
{
Return odbc_fetch_row ($ query );
}
Function total_num ($ SQL) // Retrieve the total number of records
{
Return odbc_num_rows ($ this-> query ($ SQL ));