Php dba function library and usage

Source: Internet
Author: User
Tags db2 dba ibm db2

In Berkeley's BSD operating systems, there is a simple database structure, which uses several files to form an ultra-small database system and is structured as a DBA database with an abstract action layer.

Currently, the DBA databases supported by PHP Include

  1. DBM: the earliest DBA database developed by Berkeley. Ndbm: a newer and more flexible DBA. Gdbm: GNU-developed dBA, ftp://ftp.gnu.org/pub/gnu/gdbm/


    DB2: DB2 (non-IBM DB2), http://www.sleepycat.com developed by sleepycat Software


  2. CDB: This is the Qmail author developed fast and reliable dBA, http://pobox.com /~ Djb/cdb.html


The following is a simple example. You must install DBA before using it.

<? PHP
$ Id = dba_open ("/tmp/test. DB", "n", "DB2 ");

If (! $ Id ){
Echo "dba_open failedn ";
Exit;
}

Dba_replace ("key", "This is an example! ", $ Id );

If (dba_exists ("key", $ id )){
Echo dba_fetch ("key", $ id );
Dba_delete ("key", $ id );
}

Dba_close ($ id );
?>

Dba_close: Shut down the database.
Dba_delete: Delete specified data.
Dba_exists: Check whether the key exists.
Dba_fetch: Retrieves the specified data.
Dba_firstkey: Retrieve the first key value.
Dba_insert: Add materials.
Dba_nextkey: Retrieves the next key value.
Dba_popen: Open and maintain the database link.
Dba_open: Open the database link.
Dba_optimize: Optimize the database.
Dba_replace: Modify or add materials.
Dba_sync: Database Synchronization.

Dba_close

Shut down the database.
Syntax: void dba_close (INT handle );
Return Value: None
Function Type: database functions
Description: This function is used to close an opened database. The handle parameter is the code ID returned when the database is opened.
See dba_popen () dba_open ()

Dba_delete
 
Delete specified data.

Syntax: int dba_delete (string key, int handle );
Return Value: integer
Function Type: database functions
Description: This function deletes the specified data. The parameter key is the key to be deleted ). The handle parameter is the code ID returned when the database is opened. True is returned if the deletion is successful.
See dba_exists () dba_fetch () dba_insert () dba_replace ()

Dba_exists

Check whether the key exists.
Syntax: Boolean dba_exists (string key, int handle );
Return Value: Boolean
Function Type: database functions
This function is used to check whether the specified key exists. The parameter key is the key to be checked ). The handle parameter is the code ID returned when the database is opened. If the key exists, true is returned.
See dba_delete () dba_fetch () dba_insert () dba_replace ()

Dba_fetch

Retrieves the specified data.

Syntax: String dba_fetch (string key, int handle );
Return Value: String
Function Type: database functions
This function obtains the specified information. The parameter key is the key of the data to be retrieved ). The handle parameter is the code ID returned when the database is opened. The returned value is the data string. If the data fails to be retrieved, false is returned.
See dba_exists () dba_delete () dba_insert () dba_replace ()

Dba_firstkey

Retrieve the first key value.
Syntax: String dba_firstkey (INT handle );
Return Value: String
Function Type: database functions
This function obtains the first key of the database ). The handle parameter is the code ID returned when the database is opened. The return value is the key value. If the retrieval fails, false is returned.
See dba_nextkey ()

Dba_insert
 
Add materials.
Syntax: Boolean dba_insert (string key, string value, int handle );
Return Value: Boolean
Function Type: database functions
Content Description: this function will be added to the database. The parameter key is a key-value string. The parameter value is the content of the data to be added. The handle parameter is the code ID returned when the database is opened. If the call succeeds, the return value is true.
See dba_exists () dba_fetch () dba_delete () dba_replace ()

Dba_nextkey
Retrieves the next key value.
Syntax: String dba_nextkey (INT handle );
Return Value: String
Function Type: database functions
This function obtains the next key of the database ). The handle parameter is the code ID returned when the database is opened. The return value is the key value. If the retrieval fails, false is returned.
See dba_firstkey ()

  
Dba_popen

Open and maintain the database link.
Syntax: int dba_popen (string path, string mode, string handler );
Return Value: integer
Function Type: database functions
Description: This function is used to open a specified database and maintain the connection with the database. The parameter path is the path and name of the database, for example, "/tmp/mysite/Wahaha. DB ". The following table lists the mode values.

Attribute Description
R Open read-only existing database
W Open an existing database that can be read and written
C Open the read/write database. If the database does not exist, create
N Delete the existing database. If it does not exist, the database is created and can be read and written later.

Handler is the type of open database, including dBm, ndbm, gdbm, DB2, or CDB. The return value is the database code ID. If it fails, false is returned. See dba_close () dba_open ()

  
Dba_open
Open the database link.
Syntax: int dba_open (string path, string mode, string handler );
Return Value: integer
Function Type: database functions
Description: This function is used to open a specified database. The parameter path is the path and name of the database, for example, "/tmp/mysite/Wahaha. DB ". The following table lists the mode values.

Attribute Description
R Open read-only existing database
W Open an existing database that can be read and written
C Open the read/write database. If the database does not exist, create
N Delete the existing database. If it does not exist, the database is created and can be read and written later.

 
Handler is the type of open database, including dBm, ndbm, gdbm, DB2, or CDB. The return value is the database code ID. If the return value fails
False. The difference between this function and dba_popen () is that the database opened by this function is closed after the PHP program ends. dba_popen ()
The connection to the database will be maintained, and the connection to the database will not be opened until the next execution.
See dba_close () dba_popen ()

Dba_optimize


Optimize the database.
Syntax: Boolean dba_optimize (INT handle );
Return Value: Boolean
Function Type: database functions
This function optimizes the database. The handle parameter is the code ID returned when the database is opened. If the optimization is successful, true is returned. Otherwise, false is returned.
See dba_sync ()

Dba_replace
 
Modify or add materials.
Syntax: Boolean dba_replace (string key, string value, int handle );
Return Value: Boolean
Function Type: database functions
Description: This function modifies the data in the database. If the data does not exist, add it. The parameter key is a key-value string. The parameter value is the information to be modified. The handle parameter is the code ID returned when the database is opened. If the call succeeds, the return value is true.
See dba_exists () dba_fetch () dba_delete () dba_insert ()

Dba_sync
 
Database Synchronization.
Syntax: Boolean dba_sync (INT handle );
Return Value: Boolean
Function Type: database functions
Description: This function allows the system to write data to the physical database storage device (such as hard disk) when updating the database. The handle parameter is the code ID returned when the database is opened. If the synchronization succeeds, true is returned. Otherwise, false is returned.
See dba_optimize ()

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.