Using the New Features
This section explains some of the new features and illustrates them with short examples. We show you:
How to use the new basic features
Basic examples of how to prepare and execute statements
How to profile your MySQL function calls
We don't discuss features for working with replicated servers, the new transaction features, or how to set up compressed or encrypted connections
Basic Features
With the regular library, you connect to a server and select a database using a fragment such as the following:
$connection = mysql_connect("localhost", "fred", "shhh"); mysql_select_db("winestore", $connection);
With the improved library, you can combine these two steps as follows:
$connection = mysqli_connect("localhost", "fred", "shhh", "winestore");
As shown in Example H-2, you can still use the old approach if you want to.
Both the regular and improved libraries have two query functions. The regular library has mysql_query( ) and mysql_unbuffered_query( ), while the improved library has mysqli_query( ) and mysql_real_query( ). As we showed in the previous section, mysql_query( ) and mysqli_query( ) are equivalent.
The mysqli_real_query( ) function can be used for either buffered or unbuffered output; it can provide normal output or the same features as mysql_unbuffered_query( ). After you've called mysql_real_query( ), you need to call either mysql_use_result( ) or mysql_store_result( ) to specify how results are to be retrieved. If you call mysql_use_result( ), then rows are ...
Get Web Database Applications with PHP and MySQL, 2nd Edition 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.