PHP Developer’s Dictionary IT-SC book 385 Description The sem_acquire() function blocks processing until the semaphore defined by sem_identifier can be acquired. The function returns false, 0 , if there is an error. Note Remember to release all semaphores after use. Failure to do so will result in a warning. sem_release() Syntax int sem_release(int sem_identifier); Description The sem_release() function releases the semaphore defined by sem_identifier . The function returns false, 0 , if there is an error. shm_attach() Syntax int shm_attach(int key, int [memsize], int [perm]); Description The shm_attach() function returns an ID that that can be used to access shared memory defined by key . The optional parameters memsize and perm create the shared memory segment of memsize with permissions defined by perm . The function returns false, 0 , if an error occurred. Note Calling shm_attach() a second time will return a different shared memory ID; however, both identifiers access the same shared memory. The memsize and perm arguments will be ignored. PHP Developer’s Dictionary IT-SC book 386 shm_detach() Syntax int shm_detach(int shm_identifier ); Description The shm_detach() function disconnects from the shared memory identified by shm_identifier . The shared memory must have been previously created by shm_attach() . The function returns false, 0 , on error. shm_remove() Syntax int shm_remove(int shm_identifier); Description The shm_remove() function removes shared memory identified by shm_identifier and destroys all data. This function returns false, 0 , on error. shm_put_var() Syntax int shm_put_var(int shm_identifier, int variable_key, mixed variable); Description The shm_put_var() function inserts or updates a variable in the shared memory identified by shm_identifier . The defined variable_key is updated with the value of variable . shm_get_var() Syntax PHP Developer’s Dictionary IT-SC book 387 mixed shm_get_var(int shm_identifier, int variable_key); Description The shm_get_var() function returns the variable in the shared memory space defined by shm_identifier with a given variable_key . shm_remove_var() Syntax int shm_remove_var(int shm_identifier, int variable_key); Description The shm_remove_var() function removes a variable in the shared memory space defined by shm_identifier with a given variable_key and frees the memory taken up by the variable. PHP Developer’s Dictionary IT-SC book 388 Chapter 10. Chapter Database Extensions This chapter provides a reference for all the database-related functions available with PHP. All the major—and many of the minor—relational databases are supported, both natively and in some cases, through ODBC drivers. Database support is one of the most important features of PHP and is constantly being updated, so be sure to consult the latest documentation for new functions and features. Several commonalities exist between many of the different databases supported. One commonality is connection handling. Most major databases offer both persistent and non-persistent connections. A non-persistent connection is destroyed automatically at the end of script processing, whereas a persistent connection remains even after a script has finished. Because the amount of overhead involved in establishing a connection can be significant, you will generally have better performance by using persistent connections, but you can do this only when PHP is running as a server module and not as a CGI program. Another commonality is that when a connection attempt is made, PHP looks for a similar connection and returns the reference to it instead of creating a new connection, if possible. This is true for both persistent and non-persistent connections. Some terms you should be familiar with when consulting this chapter include transaction, commit, rollback, cursor, and fetch. A transaction is a set of SQL queries that are related, typically because they build upon each other. A transaction is used to ensure that a particular process completes successfully. The typical transaction example is this: Imagine transferring money from your savings account to your checking account. The first part of the transaction would debit your savings account and the second part would credit your checking account. Of course, if either of these actions fails, you want the entire process to fail; otherwise, your money could disappear into thin air. This is the purpose of a transaction: to ensure that the entire process finishes. When you complete the transaction or process, you can call commit, which tells the database that you have finished and are confirming your changes. Rollback means to reverse your previous transaction or query. Finally, a cursor refers to the result of a query and fetch means to examine a row of the result set. For a more complete understanding of these concepts, consult any of the database vendors'reference material. Database Abstraction Layer The Database Abstraction Layer functions provide a means to work with many of the file-based databases that are available. These include Dbm, Gdbm, SleepyCat Software DB2 and DB3, and others. The underlying structure of these databases is based on key/value pairs, which provide for simple and efficient lookups. For many applications, this is all the database functionality you will need, and enables you to avoid the task of maintaining a relational database, which can often be daunting. The following example opens a database, reads the value of user123's password, and returns it to the screen: <?php $dba_handle = dba_open ("/usr/local/users.db","n","db2"); if (!$dba_handle ) { echo "user database open failed\ n"); exit; } echo "Password for user123 is:\n"; PHP Developer’s Dictionary IT-SC book 389 echo dba_fetch ("user123",$dba_handle); dba_close ($dba_handle); ?> dba_close() Syntax void dba_close(int handle) Description The dba_close() function, which was added in PHP 3.0.8 and PHP 4.0b2, closes the connection to a database indicated by the handle parameter. All resources utilized by this handle , which is created by the dba_open() function, are freed. No return value is available for this function. dba_delete() Syntax string dba_delete(string key, int handle) Description The dba_delete() function, which was added in PHP 3.0.8 and PHP 4.0b2, deletes the entry with the corresponding key from the database specified by the handle parameter. The return value is TRUE if the key is deleted and FALSE otherwise. dba_exists() Syntax bool dba_exists(string key, int handle) Description . variable. PHP Developer’s Dictionary IT-SC book 388 Chapter 10. Chapter Database Extensions This chapter provides a reference for all the database-related functions available with PHP. All. connections, but you can do this only when PHP is running as a server module and not as a CGI program. Another commonality is that when a connection attempt is made, PHP looks for a similar connection. void dba_close(int handle) Description The dba_close() function, which was added in PHP 3.0.8 and PHP 4.0b2, closes the connection to a database indicated by the handle parameter. All resources