Other Functions


MySQL also has a set of miscellaneous functions. Many of these have to do with hashing or encryption, but there are also some other very useful functions in this set. A list of the more useful ones is shown in Table 8.6.

Table 8.6. Miscellaneous Functions

Function

Purpose

benchmark( count, expression )

Evaluates expression count times. Always returns zero ”the point of this function is to time execution and look at the execution time at the bottom of the result set.

encrypt( s[,salt] )

Encrypts s using a Unix crypt system call. The salt string is an optional two-character string. If crypt is not available on your system (for example, Windows), this function will return NULL .

found_rows()

Returns the number of rows that would have been returned by the last query if no limit clause was used. Works only if SQL_CALC_FOUND_ROWS was specified in the SELECT statement, as discussed in Chapter 7.

last_insert_id()

Returns the last automatically generated AUTO_INCREMENT value. This is useful if we have inserted a row into one table and now need that row's id to insert as a foreign key into another table.

md5( s )

Returns the 128-bit MD5 hash of string s . If you are writing an application to store usernames and passwords, this is the recommended method for storing passwords in your database.

 

Encryption algorithms have a limited useful lifetime. As the power of computers increases , stronger algorithms are required. MD5 is currently regarded as fairly secure.

password( s )

Calculates a password string for the string s . This is the scheme that is used to represent MySQL user passwords, as we will discuss in Chapter 11, "Managing User Privileges." It is not recommended that you use password() to store passwords in your own applications.



MySQL Tutorial
MySQL Tutorial
ISBN: 0672325845
EAN: 2147483647
Year: 2003
Pages: 261

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net