There are so many good foreign countries. Now I am posting an ACCESS class!

Source: Internet
Author: User
Tags dbase php source code

Introduction: This is a lot of good foreign stuff. Now I am posting an ACCESS class! The details page of php, related knowledge, skills, experience, and some php source code.

Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 325327 'rolling = 'no'>

This is an ACCESS class.

<?
Class AccessDBM
{
Var $ COUNT = 0;
Var $ VALUES = array ();
Var $ FILE = "";
Var $ ERROR = "";
Var $ EXISTS = false;
Var $ STATIC = false;
Var $ EXACT = false;
Var $ DBM;

// Older version of PHP can't do the 'new ClassName (args )'
// Use initilize () if this is the case.

//************************************** *****************

Function AccessDBM ($ dbmFile, $ static = 0)
{
Global $ php_errormsg;

If (! Empty ($ dbmFile ))
{
If (file_exists ($ dbmFile ))
{
$ This-> EXISTS = true;
}
If ($ static! = 0)
{
$ This-> STATIC = true;
}
$ This-> FILE = $ dbmFile;
}
Return;
}

//************************************** *****************

// Identical to AccessDBM
Function initialize ($ dbmFile, $ static = 0)
{
Global $ php_errormsg;

If (! Empty ($ dbmFile ))
{
If (file_exists ($ dbmFile ))
{
$ This-> EXISTS = true;
}
If ($ static! = 0)
{
$ This-> STATIC = true;
}
$ This-> FILE = $ dbmFile;
}
Return;
}

//************************************** *****************

Function add_entry ($ key, $ val)
{
$ Results = 0;
$ Dbm = $ this-> open_dbm ();
If (! $ Dbm) {return false ;}

If (! (Dbmreplace ($ dbm, $ key, $ val )))
{
If (! (Dbmexists ($ dbm, $ key )))
{
$ This-> ERROR = "Fatal error: cocould not replace $ key with $ val ";
$ This-> close_dbm ($ dbm );
Return false;
}
}
$ This-> close_dbm ($ dbm );
Return true;
}

//************************************** *****************

Function remove_entry ($ Key)
{
Global $ php_errormsg;
$ Removed = false;

$ Dbm = $ this-> open_dbm ();
If (! $ Dbm) {return false ;}

If (dbmexists ($ dbm, $ Key ))
{
If (! Dbmdelete ($ dbm, $ Key ))
{
If (dbmexists ($ dbm, $ Key ))
{
$ This-> ERROR = "Unable to remove [$ Key]: [$ php_errormsg]";
$ This-> close_dbm ($ dbm );
Return false;
}
}
Else
{
$ This-> close_dbm ($ dbm );
$ Removed = true;
}
}
Else
{
$ This-> ERROR = "Key [$ Key] does not exist ";
$ This-> close_dbm ($ dbm );
Return false;
}
Return true;
}

//************************************** *****************

Function get_value ($ Key)
{
$ Val = "";
$ ReadOnly = true;

$ Dbm = $ this-> open_dbm ($ readOnly );

If (! $ Dbm) {return false ;}

If (dbmexists ($ dbm, $ Key ))
{
$ Val = dbmfetch ($ dbm, $ Key );
}
$ This-> close_dbm ($ dbm );
Return $ val;
}

//************************************** *****************

Function open_dbm ($ readOnly = false)
{
Global $ php_errormsg;

If ($ this-> STATIC)
{
If (! (Empty ($ this-> DBM )))
{
$ Dbm = $ this-> DBM;
Return ($ dbm );
}
}

$ FileName = $ this-> FILE;

If (! $ This-> EXISTS)
{
$ Dbm = @ dbmopen ($ fileName, "n ");
}
Else
{
If (! $ ReadOnly)
{
// We want the warning here if we can't be
// A writer
$ Dbm = dbmopen ($ fileName, "w ");
}
Else
{
$ Dbm = @ dbmopen ($ fileName, "r ");
}
}
If ((! $ Dbm) or (empty ($ dbm )))
{
$ This-> EXISTS = false;
$ This-> STATIC = false;
$ This-> ERROR = "Unable to open [$ fileName] [$ php_errormsg]";
Return false;
}
$ This-> EXISTS = true;
If ($ this-> STATIC)
{
$ This-> DBM = $ dbm;
}

Return ($ dbm );

}

//************************************** *****************

Function find_key ($ search)
{
$ Val = "";

$ Dbm = $ this-> open_dbm (1 );
If (! $ Dbm) {return false ;}
If (dbmexists ($ dbm, $ search ))
{
// Wow an exact match
$ Val = dbmfetch ($ dbm, $ search );
$ This-> close_dbm ($ dbm );
$ This-> EXACT = true;
Return $ val;
}
Else
{
$ This-> EXACT = false;
$ Key = dbmfirstkey ($ dbm );
While ($ key)
{
// Strip the first whitespace char and
// Everything after it.
$ Test = ereg_replace (". *", "", $ key );
If (eregi ("^ $ test", $ search ))
{
$ Val = dbmfetch ($ dbm, $ key );
$ This-> close_dbm ($ dbm );
Error_log ("Test [$ test] matched [$ search]", 0 );
Return $ val;
}
$ Key = dbmnextkey ($ dbm, $ key );
}
}
// Didn't find it
$ This-> close_dbm ($ dbm );
Return false;
}

//************************************** *****************

// Returns the KEY
Function find_val ($ search)
{
$ This-> EXACT = false;

$ Dbase = $ this-> get_all ();
If (empty ($ Dbase ))
{
Error_log ("ERROR Dbase is empty $ DB-> ERROR", 0 );
Return false;
}
While (list ($ key, $ val) = each ($ Dbase ))
{
If ($ search = $ val)
{
$ This-> EXACT = true;
Return $ key;
}
Else
{
// Strip the first whitespace char and
// Everything after it.

$ Test = ereg_replace (". *", "", $ val );

If (eregi ("^ $ test", $ search ))
{
$ This-> EXACT = false;
Return $ key;
}
}
}
// Didn't find it
Return false;
}

//************************************** *****************

Function get_all ()
{
$ Values = array ();
$ Count = 0;
$ ReadOnly = true;
$ Dbm = $ this-> open_dbm ($ readOnly );
If (! $ Dbm) {return false ;}

$ Key = dbmfirstkey ($ dbm );

While ($ key)
{
$ Val = dbmfetch ($ dbm, $ key );
$ Values [$ key] = $ val;
$ Count ++;
$ Key = dbmnextkey ($ dbm, $ key );
}
$ This-> COUNT = $ count;
$ This-> VALUES = $ values;
$ This-> close_dbm ($ dbm );
Return $ values;
}

//************************************** *****************

Function close_dbm ($ dbm)
{
$ Results = false;

If (! $ This-> STATIC)
{
$ Results = dbmclose ($ dbm );
}
Return $ results;
}

//************************************** *****************

Function static_close ()
{
$ Results = false;

If (! $ This-> DBM)
{
$ This-> ERROR = "No static DBM to close ";
Return false;
}
$ Dbm = $ this-> DBM;
$ Results = dbmclose ($ dbm );
Unset ($ this-> DBM );
Return $ results;
}

//************************************** *****************

}
?>

This connection!
Include ("class. AccessDBM. php3 ");
$ Static = true;
$ Dbase = new AccessDBM ("/path/to/file. dbm", $ static );

Register_shutdown_function ($ dbase-> static_close ());

If (! $ Dbase-> add_entry ("cdi", "cdi@thewebmasters.net ))
{
Echo "Error adding entry: $ dbase-> ERROR \ n ";
}
$ Values = $ dbase-> get_all ()
While (list ($ key, $ val) = each ($ Values ))
{
Echo "Key: $ key Val: $ val \ n ";
}
Exit;

"There are so many good foreign countries. Now I am posting an ACCESS class !" More related articles

Love J2EE follow Java Michael Jackson video station JSON online tools

Http://biancheng.dnbcw.info/php/325327.html pageNo: 14

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.