Skip to Main Content
PHP in a Nutshell
book

PHP in a Nutshell

by Paul Hudson
October 2005
Intermediate to advanced content levelIntermediate to advanced
372 pages
11h 35m
English
O'Reilly Media, Inc.
Content preview from PHP in a Nutshell

MySQL Improved

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 upward, and includes new functionality such as native commit and rollback, as well as prepared statements. As the MySQLi extension is only designed to work with MySQL 4.1 and upward, 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 headfirst with some testing, 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. That said, there are some differences between MySQL and MySQLi code. For example, mysqli_connect()'s fourth parameter lets you specify the default database to use, letting you skip the call to mysqli_select_db(). If you still want to use it, 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.

Warning

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 when there are 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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP Cookbook

PHP Cookbook

Eric A. Mann
Programming PHP

Programming PHP

Rasmus Lerdorf, Kevin Tatroe
Learning PHP

Learning PHP

David Sklar

Publisher Resources

ISBN: 0596100671Errata Page