MySQL Improved

The MySQLi functions in PHP are an attempt to provide a clean, "Improved" (hence the "i") set of functions for accessing MySQL. While they all work just fine, most people have carried on using the existing MySQL functions. However, for the sake of completeness we've covered MySQLi here.

You will be happy to hear that the MySQLi functions work similarly to the MySQL functions - you just need to add an "i" after "mysql" in your code. For example, mysql_connect() becomes mysqli_connect(), mysql_query() becomes mysqli_query(), etc. It is important to note that there will almost certainly be some differences between MySQL and MySQLi code. For example, mysqli_connect() 's fourth parameter lets you specify the default table to use, letting you skip the call to mysqli_select_db(). Mysqli_select_db() itself is also different, now taking the return value of mysqli_connect() as its first parameter, and the database to select as its second parameter.

Author's Note: If you want to install support for both MySQL and MySQLi when compiling PHP, just point them both to the same client library on your system.

 

Next chapter: Subselects, views, and other advanced functions >>

Previous chapter: Transactions

Jump to:

 

Home: Table of Contents

Follow us on Identi.ca or Twitter

Username:   Password:
Create Account | About TuxRadar