5.7. Converting mysqli Functions to mysql Functions

This book assumes you're using PHP 5 or 6 with the mysqli functions to interact with MySQL 5.0 or 5.1. If you're using PHP 4, the mysqli functions aren't available. Instead, you use the mysql functions, even with later versions of MySQL. The mysql functions can communicate with the later versions of MySQL, but they can't access some of the new features added in the later versions of MySQL. The mysql functions are activated automatically in PHP 4.

Throughout this book, the examples and scripts use MySQL 5.0 and the mysqli functions to communicate with MySQL. The PHP functions for use with MySQL 5.0 have the following general format:

mysqli_function(value,value,...);

The i in the function name stands for improved (MySQL Improved). The second part of the function name is specific to the function, usually a word that describes what the function does. In addition, the function usually requires one or more values to be passed, specifying details such as the database connection or the data location. Here are two of the mysqli functions discussed earlier in this chapter:

mysqli_connect(connection information);
mysqli_query($cxn,"SQL statement");

The corresponding mysql functions are

mysql_connect(connection information);
mysql_query("SQL statement",$cxn);

The functionality and syntax of the functions are similar, but not identical, for all functions. In particular, mysqli functions use a different process for connecting to the MySQL ...

Get PHP & MySQL® Web Development All-in-One Desk Reference for Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.