O'Reilly logo

Upgrading to PHP 5 by Adam Trachtenberg

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 3. MySQL

PHP 5 sports a new MySQL extension. While this extension is similar in spirit to the original MySQL extension, it has many new features and other improvements. To differentiate it from the original version, this extension is called the “Improved MySQL extension,” or mysqli for short.

The changes to mysqli come from two places. The majority are from new features available in MySQL 4.1. However, PHP 5 also allows mysqli to add an object-oriented interface.

Here’s a list of the major advances in mysqli:

  • Compatibility with MySQL 4.1 and above

  • Prepared statements and bound parameters

  • Object-oriented interface

  • Secure connections using SSL

Additionally, MySQL 4.1 has new SQL-level capabilities that you can use from PHP. They include:

  • Subselects

  • Transactions

  • Fulltext searching

  • Unicode support

  • Geospacial support (GIS)

On the downside, there are a few wrinkles if you want to start using mysqli with your existing PHP projects:

  • Its client libraries are not bundled with PHP 5.

  • It does not work with MySQL 4.0 and below.

  • It’s missing some mysql functions.

In a nutshell, if all your projects use MySQL 4.1 and later, and you have no legacy MySQL code, then all you need to do is download the MySQL client libraries and start using mysqli. On the other hand, you’ll have some work to do if you:

  • Want to use MySQL 4.1, but have existing mysql-based code

  • Must write code that runs under MySQL 4.0 (and below) and 4.1 (and above)

  • Want to have some applications use a MySQL 4.0 database and others use ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required