12.3 The mSQL Module


Now we cover how to create the mSQL module for PHP. This module, like the MySQL module, is very simple to implement. In fact, the function calls for mSQL are almost identical to those of the MySQL module. This is because MySQL is really an enhanced version of mSQL, which is a fast, lightweight database available from http://www.Hughes.com.au/.

 DB/msql.php <?php include_once("DB/standard.php"); function db_connect($args=array()) {     return @msql_connect($args[0]); } function db_pconnect($args=array()) {     return @msql_pconnect($args[0]); } function db_select_db($args=array()) {     if (isset($args[1])) {         return @msql_select_db($args[0], $args[1]);     }     return @msql_select_db($args[0]); } function db_close($args=array()) {     return @msql_close($args[0]); } function db_query($args=array()) {     if (isset($args[1]) {         return @msql_query($args[0], $args[1]);     }     return @msql_query($args[0]); } function db_db_query ($args=array()) {     if (isset($args[2])) {         return @msql($args[0], $args[1], $args[2]);     }     return @mysql_db_query($args[0], $args[1]); } function db_prepare($args=array()) {     return db_simulate_prepare($args); } function db_execute ($args=array()) {     $stmt = db_simulate_execute(&$args);     return db_query(array($stmt, array_shift($args))); } function db_fetchrow($args=array()){     if ($args[1] == DB_GETMODE_ASSOC) {         return @msql_fetch_array($args[0], MSQL_ASSOC);     } elseif ($args[1] == DB_GETMODE_REG) {         return @msql_fetch_array($args[0], MSQL_NUM);     }     return @msql_fetch_array($args[1]); } function db_num_rows($args=array()) {     return @msql_num_rows($args[0]); } function db_commit($args=array()) {     return(true); } function db_rollback($args=array()) {     return(false); } function db_autoCommit($args=array()) {     return(true); } function db_free_result($args=array()) {     return @msql_free_result($args[0]); } function db_errno($args=array()) {     return @msql_errno(); } function db_error($args=array()) {     return @msql_error(); } ?> 

Explanation

This module is the same as the MySQL module except for one fundamental difference. msql_connect() takes only one argument: the hostname to which you want to connect to execute your query. Therefore, only the first argument is used. This is the good thing about passing all the arguments in array form.

In the previous module, MySQL, db_connect() takes three arguments: hostname, username, and password. If we didn't take the arguments in an array form, it would cause a problem when you switch from MySQL to mSQL. But because the arguments are passed as an array, you can leave the username and password in the argument list and it will not cause anything to break.



PHP Developer's Cookbook
PHP Developers Cookbook (2nd Edition)
ISBN: 0672323257
EAN: 2147483647
Year: 2000
Pages: 351

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