9.18 MySQL ImprovedThis 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.
|
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!
|