MySQL PHP Class Compiling Queries
There are three functions you can use to compile a MySQL query, updateQuery, insertQuery and select. See the functions below.
select function
This function is used to compile custom SELECT queries from scratch and perform them. This is the most complicated function provided.
Parameters
- Values array (required) - This is an associative array of values which will be used to compile your query.
- Table str (required) - This is the name of the table you'd like to query.
Acceptable Values for the values array
- Any table column name and its respective value. See the examples below for a more in depth look into this option.
- limit - This value should be how many records would you like to return.
- offset - At which index would you like your returned record set to start.
- orderby - This should be which table column would you like to order your results by.
- order - This will determine ascending or descending order. (asc or desc).
- excludes - This should be a multi-dimensional associative array of values by which you'd like to exclude from your results.
Return Value
Returns a record set if any records are found and FALSE if no records are returned.
Examples
The following is a very simple example of the select function.
$connection->select(array( 'id' => 1000 ),'table_name');
This example shows how to select a range of id's in between 1000 and 2000 starting at the 10th record found limited to 100 records and excluding any record with an 'id' of 1100 or 1101.
$connection->select(array( 'id' => 'range:1000-2000', 'limit' => 100, 'offset' => 10, 'excludes' => array( 'id' => array(1100,1101) ) ),'table_name');
This next example shows how to select any records that have an 'id' greater than 1000, a name which contains the word 'John', a name which does not contain the word 'Jingle', a value of less than 200 in the 'loggedin' column. Also the record set will start at the 10th record found, will be limited to 100 records and will exclude any record with an 'id' of 1100 or 1101.
$connection->select(array( 'id' => 'greater:1000', 'name' => 'contains:John&no:Jingle', 'loggedin' => 'lesser:200', 'limit' => 100, 'offset' => 10, 'excludes' => array( 'id' => array(1100,1101) ) ),'table_name');