My blasting through as many projects as I can has brought me to the PHP-MySQL library.
This is part of my resolution to write a post on each of my
Let's hope I can keep up this pace :)
The PHP-MySQL project is designed to provide helper functions that present a clean API (method) to connect to a MySQL engine (persistently), in addition to executing MySQL queries.
It contains two files that facilitate this.
If you look at the examples, you'll be able to see the desire to have the code be both clean and succinct. I wanted to have a way to create a persistent connection to an engine, and be able to perform queries against that connection without having to pass the connection resource around (despite PHP not explicitly requiring that).
This library includes two classes. One is static (the connection class), while the other is instantiable (to have MySQL queries treatable as objects).
While I may ordinarily include a quick run through of the public methods, I believe the Sample MySQL Query shows clearly the basic usage of it.
The two classes themselves are:
MySQLConnectionHandles a persistent connection to the engine
MySQLQueryPerforms and handles queries against the persistent connection
In order to use this library, upon server request (presumably), you would initiate a connection to the database with the supplied host, port, username and password.
Beyond this, new
MySQLQuery objects can be created. Queries are performed
immediately upon object instantiation, but can (and most of the time will) be
assigned to variables.
These variables have various methods available to them, most likely to be used
getResults method which returns the results from the execution.
MySQLConnection class has analytical methods available to it,
getStats which may be useful during development or debugging.
I wanted the connection and execution of queries to be decoupled from the building of them, which can be seen in the PHP-Query library.
Additionally, I wanted to be able to analyze the query and connection performance. This is especially useful in larger, complicated queries, where a table may need to be optimized with indexes, etc.
And which project is next? Youuuu guessed it! PHP-Query!