Databases Reference
In-Depth Information
The descriptions in this section are simplified. We've omitted function parameters that
are rarely used, avoided some of the details of how the functions are used, and shown
some optional parameters as mandatory. We've also shown only the procedural style
for the library, which means we've shown the features of the library as functions; you
can also use the new library in an object-oriented programming style, but that's outside
the scope of this topic. You'll find more detail on MySQLi functions in the PHP manual
at http://www.php.net/manual/en/ref.mysqli.php and in the resources listed in “Resour-
ces” at the end of this chapter.
What's New in MySQLi
The examples and functions we've discussed don't show the differences between the
MySQL and MySQLi libraries; let's look at these now. The most significant difference
between the libraries is under the hood. The MySQLi library is a complete rewrite of
the MySQL library, designed to offer better performance. This means that even if you're
not using the advanced features it offers, it's always better to use MySQLi when you're
not constrained by other issues (such as maintaining legacy code). Other features of
MySQLi include:
Support for encrypted and compressed connections
These allow faster, secure connections between PHP and MySQL over a network.
Encryption using SSL is highly secure and ensures that hackers can't eavesdrop on
your data as it is being transmitted. Compression means that less data is transferred
between the web server and the MySQL server, which for moderate or high rates
of data transfer means that communications are faster.
Prepared statements
These allow you to prepare (parse, optimize, and plan) an SQL statement once and
reuse it many times, saving that cost each time you use it. This is useful if you want
to repeat a query with different parameters—for example, when bulk inserting
data.
Object-oriented methods
As discussed previously, you can now use an object-oriented style with the MySQLi
library in addition to the procedural style shown in this section.
Transaction control
Transactions are discussed in “Transactions and Locking” in Chapter 7. The
MySQLi library gives you functions to turn the autocommit feature on or off, and
also start, commit, and roll back transactions.
Profiling
Allows you to view statistics and debugging information from your MySQL server.
This includes timing details for function calls, the output of the EXPLAIN statement
that describes how the queries are evaluated, and so on.
 
Search WWH ::




Custom Search