negative(-11) Documentation

Documentation Home

MySQL Abstraction Layer

The MySQL pacakge provides a simple database interface that uses the MySQL Improved API built into the standard PHP distribution. Essentially a wrapper, it provides quick access to the most needed functionality: connect, query, fetch result, walk away. There are a a few extra bonuses, such as result iteration and query binding, to make life easier.

Connecting

A connection is established upon construction of the object. All parameters are specified via the Registry, for which you can configure multiple connections. Once an instance has been created via a call to new Mysqli_Component, you are ready to use the connection.

Querying

Simply call the query() method of a connection instance to query the database. A sample query has been supplied, along with some test data, in the Mysql_Test_Controller that comes with the package. The sample query demonstrates how to supply and bind an arbitrary number of SQL parameters. Such parameters are escaped automatically, eliminating the need to call escape methods manually.

Getting the Result

The Mysql_Component doesn't actually perform the query you supply it. Instead, it logs it, then delegates the execution of the query to the Mysqli_Result_Component class. After calculating the number of rows, the result object is returned to the caller. The result object may be treated just like an array, so all the common methods are available: count(), reset(), previous(), next(), and so forth. You can even use the foreach() construct to iterate through all of the items in a result.


© Copyright 2010 negative11.com