Приглашаем посетить
CSS (css.find-info.ru)

Section 14.5.  MySQL Improved

Previous
Table of Contents
Next

14.5. 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 functionsyou 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.

Section 14.5.  MySQL Improved

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 between MySQL and MySQLi, do not try to differentiate between false and null.


Section 14.5.  MySQL Improved

If you want to install support for both MySQL and MySQLi when compiling PHP, just point with-mysql and with-mysqli to the MySQL 4.1 client library on your system.



Previous
Table of Contents
Next