SQL
Contains the database settings and functions for interacting with the SQL database.
Summary
| SQL | Contains the database settings and functions for interacting with the SQL database. |
| Files | |
| Query | Query |
| QueryBuilder | QueryBuilder |
| Variables | |
| $debug | Holds debug information for SQL queries. |
| $queries | Number of queries it takes to load the page. |
| $db | Holds the currently running database. |
| $error | Holds an error message from the last attempted query. |
| Functions | |
| __construct | The class constructor is private so there is only one connection. |
| method | Returns the proper method of connecting and interacting with the database. |
| set | Sets a variable’s value. |
| connect | Connects to the SQL database. |
| query | Executes a query and increases SQL->$queries. If the query results in an error, it will die and show the error. |
| count | Performs a counting query and returns the number of matching rows. |
| select | Performs a SELECT with given criteria and returns the query result object. |
| insert | Performs an INSERT with given data. |
| replace | Performs a REPLACE with given data. |
| update | Performs an UDATE with given criteria and data. |
| delete | Performs a DELETE with given criteria. |
| latest | Returns the last inserted ID. |
| escape | Escapes a string, escaping things like $1 and C:\foo\bar so that they don’t get borked by the preg_replace. This also handles calling the SQL connection method’s “escape_string” functions. |
| year_from_datetime | Returns the year of a datetime. |
| month_from_datetime | Returns the month of a datetime. |
| day_from_datetime | Returns the day of a datetime. |
| hour_from_datetime | Returns the hour of a datetime. |
| minute_from_datetime | Returns the minute of a datetime. |
| second_from_datetime | Returns the second of a datetime. |
| current | Returns a singleton reference to the current connection. |
query
| public function query( | $query, | |||
| $params | = | array(), | ||
| $throw_exceptions | = | false | ) |
Executes a query and increases SQL->$queries. If the query results in an error, it will die and show the error.
Parameters
| $query | Query to execute. |
| $params | An associative array of parameters used in the query. |
| $throw_exceptions | Should an exception be thrown if the query fails? |
count
| public function count( | $tables, | |||
| $conds | = | null, | ||
| $params | = | array(), | ||
| $throw_exceptions | = | false | ) |
Performs a counting query and returns the number of matching rows.
Parameters
| $tables | An array (or string) of tables to count results on. |
| $conds | An array (or string) of conditions to match. |
| $params | An associative array of parameters used in the query. |
| $throw_exceptions | Should exceptions be thrown on error? |
select
| public function select( | $tables, | |||
| $fields | = | "*", | ||
| $conds | = | null, | ||
| $order | = | null, | ||
| $params | = | array(), | ||
| $limit | = | null, | ||
| $offset | = | null, | ||
| $group | = | null, | ||
| $left_join | = | array(), | ||
| $throw_exceptions | = | false | ) |
Performs a SELECT with given criteria and returns the query result object.
Parameters
| $tables | An array (or string) of tables to grab results from. |
| $fields | Fields to select. |
| $conds | An array (or string) of conditions to match. |
| $order | ORDER BY statement. Can be an array. |
| $params | An associative array of parameters used in the query. |
| $limit | Limit for results. |
| $offset | Offset for the select statement. |
| $group | GROUP BY statement. Can be an array. |
| $left_join | An array of additional LEFT JOINs. |
| $throw_exceptions | Should exceptions be thrown on error? |
insert
| public function insert( | $table, | |||
| $data, | ||||
| $params | = | array(), | ||
| $throw_exceptions | = | false | ) |
Performs an INSERT with given data.
Parameters
| $table | Table to insert to. |
| $data | An associative array of data to insert. |
| $params | An associative array of parameters used in the query. |
| $throw_exceptions | Should exceptions be thrown on error? |
replace
| public function replace( | $table, | |||
| $data, | ||||
| $params | = | array(), | ||
| $throw_exceptions | = | false | ) |
Performs a REPLACE with given data.
Parameters
| $table | Table to insert to. |
| $data | An associative array of data to insert. |
| $params | An associative array of parameters used in the query. |
| $throw_exceptions | Should exceptions be thrown on error? |
update
| public function update( | $table, | |||
| $conds, | ||||
| $data, | ||||
| $params | = | array(), | ||
| $throw_exceptions | = | false | ) |
Performs an UDATE with given criteria and data.
Parameters
| $table | Table to update. |
| $conds | Rows to update. |
| $data | An associative array of data to update. |
| $params | An associative array of parameters used in the query. |
| $throw_exceptions | Should exceptions be thrown on error? |
delete
| public function delete( | $table, | |||
| $conds, | ||||
| $params | = | array(), | ||
| $throw_exceptions | = | false | ) |
Performs a DELETE with given criteria.
Parameters
| $table | Table to delete from. |
| $conds | Rows to delete.. |
| $params | An associative array of parameters used in the query. |
| $throw_exceptions | Should exceptions be thrown on error? |