Hudzilla.org - the homepage of Paul Hudson
Contents > Databases Wish List | Report Bug | About Me ]

9.18     MySQL Improved

This is NOT the latest copy of this book; click here for the latest version.

New with PHP 5 is the MySQLi extension, which is "MySQL Improved". This is an all-new extension designed to take advantage of the new features available from MySQL 4.1 and upwards, and includes new functionality such as native commit and rollback, as well as prepared statements.

At the time of writing, MySQL 4.1 has yet to be declared stable, and is not likely to be declared stable for some time yet. Furthermore, as the MySQLi extension is only designed to work with MySQL 4.1 upwards, it isn't likely to see any widespread use for some time.

If you are an early adopter of MySQL 4.1 and want to jump in head first with some testing, 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.

As MySQL 4.1 is not yet released, the MySQLi extension can be said to be "under development", although it isn't directly marked as experimental - I strongly recommend you check the latest documentation before experimenting with the new extension. The MySQLi extension is likely to take over from the MySQL extension once MySQL 4.1 has reached a critical mass of popularity. At the time of writing, MySQL 4.1 has been declared "gamma", which is a rare term in computing (and nearly unique to MySQL!) that is applied to software more stable than alpha and beta, but still not fully tested enough to be declared "production-quality". At this point it's only a matter of time before MySQL 4.1 reaches general availability.

Author's Note: At the time of writing, three MySQLi functions had potentially serious incompatibilities with their MySQL cousins. All three of mysqli_fetch_row(), mysqli_fetch_array(), and mysqli_fetch_assoc() return null in the case of, "no more rows to be found", as opposed to the "false" that the MySQL extension would have returned. If you want to keep your code easily portable between MySQL and MySQLi, do not try to differentiate between false and null.

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.





<< 9.17 Transactions   9.19 Subselects, views, and other advanced functions >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
A PHP Addict - 06 Sep 2008

Now that MySQL 4.1/MySQLi <b>is</b> stable, you should add a section that goes into detail about the new features MySQLi offers.

A PHP User - 06 Sep 2008

Maybe time to tell the readers of this book that MySQL 4.1 has been marked Production/Stable since Oct 04 (4.1.7)



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is seven plus one?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow