Chyrp

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.

Files

Query

See Also

Query

QueryBuilder

See Also

QueryBuilder

Variables

$debug

public $debug

Holds debug information for SQL queries.

$queries

public $queries

Number of queries it takes to load the page.

$db

public $db

Holds the currently running database.

$error

public $error

Holds an error message from the last attempted query.

Functions

__construct

private function __construct()

The class constructor is private so there is only one connection.

method

public function method()

Returns the proper method of connecting and interacting with the database.

set

public function set( $setting,   
$value,   
$overwrite  =  true )

Sets a variable’s value.

Parameters

$setting The setting name.
$value The new value.  Can be boolean, numeric, an array, a string, etc.
$overwrite If the setting exists and is the same value, should it be overwritten?

connect

public function connect( $checking  =  false )

Connects to the SQL database.

Parameters

$checking Return a boolean of whether or not it could connect, instead of showing an error.

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?

latest

public function latest()

Returns the last inserted ID.

escape

public function escape( $string,   
$quotes  =  true )

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

public function year_from_datetime( $datetime )

Returns the year of a datetime.

month_from_datetime

public function month_from_datetime( $datetime )

Returns the month of a datetime.

day_from_datetime

public function day_from_datetime( $datetime )

Returns the day of a datetime.

hour_from_datetime

public function hour_from_datetime( $datetime )

Returns the hour of a datetime.

minute_from_datetime

public function minute_from_datetime( $datetime )

Returns the minute of a datetime.

second_from_datetime

public function second_from_datetime( $datetime )

Returns the second of a datetime.

current

public static function & current()

Returns a singleton reference to the current connection.