Functions

Function Description
backup Backs up the entire database to a given file.
compareTables Returns a list of SQL commands required to turn one table into another.
connect Sets up the internal connections to the MySQL server(s).
delete Deletes a row in the given table
describeTable Gives in depth information about a MySQL table's structure and keys.
drawColumnSelectOptions Draws the <select> options of all the columns in a table.
drawTableSelectOptions Draws the <select> options for all of tables in the database excluding bigtree_ prefixed tables.
dumpTable Returns an array of INSERT statements for the rows of a given table.
escape Equivalent to mysql_real_escape_string.
exists Checks to see if an entry exists for given key/value pairs.
fetch Equivalent to calling mysql_fetch_assoc on a query.
fetchAll Returns all remaining rows for the active query.
fetchAllSingle Equivalent to the fetchAll method but only the first column of each row is returned.
fetchSingle Equivalent to the fetch method but only the first column of the row is returned.
insert Inserts a row into the database and returns the primary key
insertID Equivalent to calling mysql_insert_id.
nextColumnDefinition Return the next SQL name definition from a string.
prepareData Processes form data into values understandable by the MySQL table.
query Queries the MySQL server(s).
rows Equivalent to calling mysql_num_rows.
tableExists Determines whether a SQL table exists.
unique Retrieves a unique version of a given field for a table.
update Updates a row in the database

backup

Backs up the entire database to a given file.

Return Value: true if successful.

static backup($file, $ = [])
Parameter Description
$file Full file path to dump the database to.
$

compareTables

Returns a list of SQL commands required to turn one table into another.

Return Value: An array of SQL calls to perform to turn Table A into Table B.

static compareTables($table_a, $table_b)
Parameter Description
$table_a The table that is being translated
$table_b The table that the first table will become

connect

Sets up the internal connections to the MySQL server(s).

static connect()

delete

Deletes a row in the given table

Return Value: true if successful (even if no rows match)

static delete($table, $id)
Parameter Description
$table The table to insert a row into
$id The ID of the row to delete (or an associate array of key/value pairs to match)

describeTable

Gives in depth information about a MySQL table's structure and keys.

Return Value: An array of table information or null if the table doesn't exist.

static describeTable($table)
Parameter Description
$table The table name.

drawColumnSelectOptions

Draws the <select> options of all the columns in a table.

static drawColumnSelectOptions($table, $default = null, $sorting = false)
Parameter Description
$table The table to draw the columns for.
$default The currently selected value.
$sorting Whether to duplicate columns into "ASC" and "DESC" versions.

drawTableSelectOptions

Draws the <select> options for all of tables in the database excluding bigtree_ prefixed tables.

static drawTableSelectOptions($default = null)
Parameter Description
$default The currently selected value.

dumpTable

Returns an array of INSERT statements for the rows of a given table.
The INSERT statements will be binary safe with binary columns requested in hex.

Return Value: An array.

static dumpTable($table)
Parameter Description
$table Table to pull data from.

escape

Equivalent to mysql_real_escape_string.
Escapes non-string values by first encoding them as JSON.

Return Value: Escaped string

static escape($string)
Parameter Description
$string Value to escape

exists

Checks to see if an entry exists for given key/value pairs.

Return Value: true if a row already exists that matches the passed in key/value pairs.

static exists($table, $values, $ignored_id = null)
Parameter Description
$table The table to search
$values An array of key/value pairs to match against (i.e. "id" => "10") or just an ID
$ignored_id An ID to ignore

fetch

Equivalent to calling mysql_fetch_assoc on a query.
If a query string is passed rather than a chained call it will return a single row after executing the query.

Return Value: A row from the active query (or false if no more rows exist)

fetch($query, $parameters)
Parameter Description
$query Optional, a query to execute before fetching
$parameters Additional parameters to send to the query method

fetchAll

Returns all remaining rows for the active query.
If a query string is passed rather than a chained call it will return the results after executing the query.

Return Value: An array of rows from the active query.

fetchAll($query, $parameters)
Parameter Description
$query Optional, a query to execute before fetching
$parameters Additional parameters to send to the query method

fetchAllSingle

Equivalent to the fetchAll method but only the first column of each row is returned.

Return Value: An array of the first column of each row from the active query.

fetchAllSingle($query, $parameters)
Parameter Description
$query Optional, a query to execute before fetching
$parameters Additional parameters to send to the query method

fetchSingle

Equivalent to the fetch method but only the first column of the row is returned.

Return Value: The first column from the returned row.

fetchSingle($query, $parameters)
Parameter Description
$query Optional, a query to execute before fetching
$parameters Additional parameters to send to the query method

insert

Inserts a row into the database and returns the primary key

Return Value: Primary key of the inserted row or null if failed

static insert($table, $values)
Parameter Description
$table The table to insert a row into
$values An associative array of columns and values (i.e. "column" => "value")

insertID

Equivalent to calling mysql_insert_id.

Return Value: The primary key for the most recently inserted row.

static insertID()

nextColumnDefinition

Return the next SQL name definition from a string.

Return Value: A string.

static nextColumnDefinition($string)
Parameter Description
$string A string with the name definition being terminated by a single `

prepareData

Processes form data into values understandable by the MySQL table.

Return Value: Array of data safe for MySQL.

static prepareData($table, $data, $existing_description = null)
Parameter Description
$table The table to prepare data for
$data Array of key->value pairs
$existing_description If the table has already been described, pass it in instead of making prepareData do it again. (defaults to false)

query

Queries the MySQL server(s).
If you pass additional parameters "?" characters in your query statement
will be replaced with escaped values in the order they are found.

Return Value: Another instance of BigTree\SQL for chaining fetch, fetchAll, insertID, or rows methods.

static query($query, $...)
Parameter Description
$query The MYSQL query to execute
$... Optional parameters that will invoke MySQL prepared statement fills

rows

Equivalent to calling mysql_num_rows.

Return Value: Number of rows for the active query.

rows($query)
Parameter Description
$query Optional returned query object (defaults to using chained method)

tableExists

Determines whether a SQL table exists.

Return Value: true if table exists, otherwise false.

static tableExists($table)
Parameter Description
$table The table name.

unique

Retrieves a unique version of a given field for a table.
Appends trailing numbers to the string until a unique version is found (i.e. value-2)
Useful for creating unique routes.

Return Value: Unique version of value.

static unique($table, $field, $value, $id = null, $inverse = false)
Parameter Description
$table Table to search
$field Field that must be unique
$value Value to check
$id An optional ID for a record to disregard (either a single value for checking "id" column or key/value pair)
$inverse Set to true to force the id column to true rather than false

update

Updates a row in the database

Return Value: true if successful (even if no rows match)

static update($table, $id, $values)
Parameter Description
$table The table to insert a row into
$id The ID of the row to update (or an associate array of key/value pairs to match)
$values An associative array of columns and values (i.e. "column" => "value")