AutoInsertUpdate()
BeginningOfSeek()
BuildSQLDelete()
BuildSQLInsert()
BuildSQLSelect()
BuildSQLUpdate()
BuildSQLValue()
BuildSQLWhereClause()
Close()
CreateDatabase()
DeleteRows()
Dump()
EndOfSeek()
Error()
ErrorNumber()
GetBooleanValue()
GetColumnComments()
GetColumnCount()
GetColumnDataType()
GetColumnID()
GetColumnLength()
GetColumnName()
GetColumnNames()
GetHTML()
GetJSON()
GetLastInsertID()
GetLastSQL()
GetStatistics()
GetTables()
GetXML()
HasRecords()
InsertRow()
IsConnected()
IsDateStr()
Kill()
MoveFirst()
MoveLast()
MyDyingMessage()
Open()
Query()
QueryArray()
QueryObjects()
QuerySingleRow()
QuerySingleRowArray()
QuerySingleValue()
QueryTimed()
Records()
RecordsArray()
RecordsObjects()
Release()
Row()
RowArray()
RowCount()
SQLBooleanValue()
SQLFix()
SQLUnfix()
SQLValue()
Seek()
SeekPosition()
SelectArray()
SelectDatabase()
SelectObjects()
SelectRows()
SelectSingleRow()
SelectSingleRowArray()
SelectSingleValue()
SelectTable()
TimerDuration()
TimerStart()
TimerStop()
TransactionBegin()
TransactionEnd()
TransactionRollback()
TruncateTable()
UpdateRow()
__construct()
__destruct()
BuildSQLColumns()
ResetError()
SetError()
$InDevelopmentEnvironment
$ThrowExceptions
$active_row
$db_charset
$db_charsetcollation
$db_dbname
$db_host
$db_pass
$db_pcon
$db_user
$error_desc
$error_number
$in_transaction
$last_insert_id
$last_result
$last_sql
$mysql_link
$query_count
$time_diff
$time_start
SQLVALUE_BIT
SQLVALUE_BOOLEAN
SQLVALUE_DATE
SQLVALUE_DATETIME
SQLVALUE_ENUMERATE
SQLVALUE_NUMBER
SQLVALUE_TEXT
SQLVALUE_TIME
SQLVALUE_T_F
SQLVALUE_Y_N
Ultimate MySQL Wrapper Class
AutoInsertUpdate(string $tableName, array $valuesArray, array | string $whereArray) : boolean
Automatically does an INSERT or UPDATE depending on whether a record already exists in a table.
string
The name of the table
array
An associative array containing the column names as keys and values as data. The values must be SQL ready (i.e. quotes around strings, formatted dates, etc.)
array
string
An associative array containing the column names as keys and values as data. The values must be SQL ready (i.e. quotes around strings, formatted dates, etc.).
This parameter may alternatively be a string, in which case it is used verbatim for the WHERE clause of the query. This is useful when advanced queries are constructed.
boolean
Returns TRUE on success or FALSE on errorBeginningOfSeek() : boolean
Returns true if the internal pointer is at the beginning of the record set produced by the last query.
boolean
TRUE if at the first row or FALSE if notif ($db->BeginningOfSeek()) { echo "We are at the beggining of the record set"; }
BuildSQLDelete(string $tableName, array | string $whereArray) : string
string
The name of the table
array
string
(Optional) An associative array containing the column names as keys and values as data. The values must be SQL ready (i.e. quotes around strings, formatted dates, etc.). If not specified then all values in the table are deleted.
This parameter may alternatively be a string, in which case it is used verbatim for the WHERE clause of the query. This is useful when advanced queries are constructed.
string
Returns the SQL DELETE statement// Let's create an array for the example // $arrayVariable["column name"] = formatted SQL value $filter["ID"] = MySQL::SQLValue(7, MySQL::SQLVALUE_NUMBER); // Echo out the SQL statement echo MySQL::BuildSQLDelete("MyTable", $filter);
BuildSQLInsert(string $tableName, array $valuesArray) : string
string
The name of the table
array
An associative array containing the column names as keys and values as data. The values must be SQL ready (i.e. quotes around strings, formatted dates, etc.)
string
Returns a SQL INSERT statement// Let's create an array for the example // $arrayVariable["column name"] = formatted SQL value $values["Name"] = MySQL::SQLValue("Violet"); $values["Age"] = MySQL::SQLValue(777, MySQL::SQLVALUE_NUMBER); // Echo out the SQL statement echo MySQL::BuildSQLInsert("MyTable", $values);
BuildSQLSelect(string $tableName, array | string $whereArray, array | string $columns, array | string $sortColumns, integer | string $limit) : string
note | Any of the parameters $whereArray, $columns, $sortColumns or $limit may alternatively be a string, in which case these are used verbatim in the query. This is useful when advanced queries are constructed. |
---|
string
The name of the table
array
string
(Optional) An associative array containing the column names as keys and values as data. The values must be SQL ready (i.e. quotes around strings, formatted dates, etc.)
array
string
(Optional) The column or list of columns to select
array
string
(Optional) Column or list of columns to sort by. Column names may be prefixed by a plus(+) or minus(-) to indicate sort order. Default is ASCending for each column.
integer
string
(Optional) The limit of rows to return
string
Returns a SQL SELECT statement// Let's create an array for the example // $arrayVariable["column name"] = formatted SQL value $values["Name"] = MySQL::SQLValue("Violet"); $values["Age"] = MySQL::SQLValue(777, MySQL::SQLVALUE_NUMBER); // Echo out the SQL statement echo MySQL::BuildSQLSelect("MyTable", $values);
BuildSQLUpdate(string $tableName, array $valuesArray, array | string $whereArray) : string
string
The name of the table
array
An associative array containing the column names as keys and values as data. The values must be SQL ready (i.e. quotes around strings, formatted dates, etc.)
array
string
(Optional) An associative array containing the column names as keys and values as data. The values must be SQL ready (i.e. quotes around strings, formatted dates, etc.). If not specified then all values in the table are updated.
This parameter may alternatively be a string, in which case it is used verbatim for the WHERE clause of the query. This is useful when advanced queries are constructed.
string
Returns a SQL UPDATE statement// Let's create two arrays for the example // $arrayVariable["column name"] = formatted SQL value $values["Name"] = MySQL::SQLValue("Violet"); $values["Age"] = MySQL::SQLValue(777, MySQL::SQLVALUE_NUMBER); $filter["ID"] = MySQL::SQLValue(10, MySQL::SQLVALUE_NUMBER); // Echo out some SQL statements echo MySQL::BuildSQLUpdate("Test", $values, $filter)";
BuildSQLValue(\arbitrary $value) : string
This methos invokes self::SQLValue() under the hood.
\arbitrary
The value to be checked and processed. Usually this would be a string, but any other type which can be cast to a string is fine as well.
string
Returns a string containing the SQL query ready value.BuildSQLWhereClause(array | string $whereArray) : string
If a key is specified, the key is used at the field name and the value as a comparison. If a key is not used, the value is used as the clause.
array
string
An associative array containing the column names as keys and values as data. The values must be SQL ready (i.e. quotes around strings, formatted dates, etc.).
This parameter may alternatively be a string, in which case it is returned verbatim. This is useful when advanced queries are constructed and this method is invoked internally.
string
Returns a string containing the SQL WHERE clauseClose() : object
object
Returns TRUE on success or FALSE on error$db->Close();
CreateDatabase(string $database, string $charset, string $collation, string $admin_user, string $admin_pass) : boolean
string
Database name
string
(Optional) Character set (i.e. utf8)
string
(Optional) Character set collation (i.e. utf8_unicode_ci)
string
(Optional) Database admin user name
string
(Optional) Database admin password
boolean
Returns TRUE on success or FALSE on errorDeleteRows(string $tableName, array | string $whereArray) : boolean
Deletes rows in a table based on a WHERE filter (can be just one or many rows based on the filter).
string
The name of the table
array
string
(Optional) An associative array containing the column names as keys and values as data. The values must be SQL ready (i.e. quotes around strings, formatted dates, etc.). If not specified then all values in the table are deleted.
This parameter may alternatively be a string, in which case it is used verbatim for the WHERE clause of the query. This is useful when advanced queries are constructed.
boolean
Returns TRUE on success or FALSE on error// $arrayVariable["column name"] = formatted SQL value $filter["ID"] = 7; // Execute the delete $result = $db->DeleteRows("MyTable", $filter); // If we have an error if (!$result) { // Show the error and kill the script $db->Kill(); }
Dump(string $tables, boolean $with_sql_comments, boolean $with_structure, boolean $with_data, boolean $with_drops_and_truncates, boolean $alter_database) : string
Produces a SQL script representing the dump of the entire database (when no (optional, comma-separated set of) tables has been specified as a method argument) or just the specified (comma separated set of) tables. You may choose to have either the database/table structure or the records dumped. Or both, for a full-fledged database/table dump which can serve as a db/table backup/restore script later on.
string
[Optional] Comma separated list of tables. When none are specified, the entire database is assumed (this is the default).
boolean
[Optional] Include SQL comments in the generated script (default: TRUE).
boolean
[Optional] Whether to include the table structure creation (and tear-down) SQL statements in the generated script (default: TRUE).
boolean
[Optional] Whether to include the table rows (data) in the generated script (default: TRUE).
boolean
[Optional] Whether to include the apropriate DROP TABLE and/or TRUNCATE TABLE statements in the generated script (default: TRUE).
boolean
[Optional] Whether to include the apropriate ALTER DATABASE statement in the generated script to set the default database charset and collation (default: TRUE).
string
the generated SQL script, boolean FALSE when a query error occurred.EndOfSeek() : boolean
boolean
TRUE if at the last row or FALSE if notif ($db->EndOfSeek()) { echo "We are at the end of the record set"; }
Error() : string
note | The returned error description string is appended with the error number itself as ' (#error_number)'. |
---|
string
Error text from last known errorif (!$db->Query("SELECT * FROM Table")) { echo $db->Error(); // Shows the error } if ($db->Error()) $db->Kill();
ErrorNumber() : integer
integer
Error number from last known errorif ($db->ErrorNumber() <> 0) { $db->Kill(); // show the error message }
GetBooleanValue(mixed $value) : boolean
mixed
Value to analyze for TRUE or FALSE
boolean
Returns TRUE or FALSEecho (MySQL::GetBooleanValue("Y") ? "True" : "False"); echo (MySQL::GetBooleanValue("no") ? "True" : "False"); echo (MySQL::GetBooleanValue("TRUE") ? "True" : "False"); echo (MySQL::GetBooleanValue(1) ? "True" : "False");
GetColumnComments(string $table) : array
string
Table name
array
An array that contains the column comments
or FALSE on error.$columns = $db->GetColumnComments("MyTable"); foreach ($columns as $column => $comment) { echo $column . " = " . $comment . "<br />\n"; }
GetColumnCount(string $table) : integer
string
(Optional) If a table name is not specified, the column count is returned from the last query
integer
The total count of columns or FALSE on errorecho "Total Columns: " . $db->GetColumnCount("MyTable");
GetColumnDataType(\intege | string $column, string $table) : string
\intege
string
Column name or number (first column is 0)
string
(Optional) If a table name is not specified, the last returned records are used
string
The MySQL data (field) type. If the column does not
exist or no records exist, return FALSE.echo "Type: " . $db->GetColumnDataType("FirstName", "Customer");
GetColumnID(string $column, string $table) : integer
string
Column name
string
(Optional) If a table name is not specified, the last returned records are used.
integer
Column ID or FALSE on error.echo "Column Position: " . $db->GetColumnID("FirstName", "Customer");
GetColumnLength(string $column, string $table) : integer
string
Column name
string
(Optional) If a table name is not specified, the last returned records are used.
integer
Field length or FALSE on error.echo "Length: " . $db->GetColumnLength("FirstName", "Customer");
GetColumnName(string $columnID, string $table) : string
string
Column position (0 is the first column)
string
(Optional) If a table name is not specified, the last returned records are used.
string
The field name for a specified column number. If
the given column index number is invalid (does not exist)
or no records exist, return FALSE.echo "Column Name: " . $db->GetColumnName(0);
GetColumnNames(string $table) : array
string
(Optional) If a table name is not specified, the last returned records are used
array
An array that contains the column names or FALSE on error.$columns = $db->GetColumnNames("MyTable"); foreach ($columns as $columnName) { echo $columnName . "<br />\n"; }
GetHTML(boolean $showCount, string $styleTable, string $styleHeader, string $styleData) : string
boolean
(Optional) TRUE if you want to show the row count, FALSE if you do not want to show the count
string
(Optional) table tag attributes, e.g. styling
string
(Optional) header row tag attributes
string
(Optional) cell tag attributes
string
HTML containing a table with all records listed or FALSE on error$db->Query("SELECT * FROM Customer"); echo $db->GetHTML();
GetJSON() : string
string
JSON containing all records listedGetLastInsertID() : integer
integer
ID number from previous INSERT query$sql = "INSERT INTO Employee (Name) Values ('Bob')"; if (!$db->Query($sql)) { $db->Kill(); } echo "Last ID inserted was: " . $db->GetLastInsertID();
GetLastSQL() : string
string
Current SQL query string$sql = "INSERT INTO Employee (Name) Values ('Bob')"; if (!$db->Query($sql)) $db->Kill(); echo $db->GetLastSQL();
GetStatistics() : array
array
Returns an array of statistics values on success or FALSE on error.GetTables(string $filter) : array
string
[Optional] Comma separated list of acceptable table names: no other table will be listed in the results. Alternatively, when no filter is specified, all tables are listed. This is the default behaviour of this method.
array
An array that contains the table names. If the database
does not contain any tables, the returned value is FALSE.$tables = $db->GetTables(); foreach ($tables as $table) { echo $table . "<br />\n"; }
GetXML() : string
string
XML containing all records listedHasRecords(string $sql) : boolean
string
[Optional] If specified, the query is first executed Otherwise, the last query is used for comparison
boolean
TRUE if records exist, FALSE if not or query errorInsertRow(string $tableName, array $valuesArray) : integer
string
The name of the table
array
An associative array containing the column names as keys and values as data. The values must be SQL ready (i.e. quotes around strings, formatted dates, etc.)
integer
Returns last insert ID on success or FALSE on failure// $arrayVariable["column name"] = formatted SQL value $values["Name"] = MySQL::SQLValue("Violet"); $values["Age"] = MySQL::SQLValue(777, MySQL::SQLVALUE_NUMBER); // Execute the insert $result = $db->InsertRow("MyTable", $values); // If we have an error if (!$result) { // Show the error and kill the script $db->Kill(); } else { // No error, show the new record's ID echo "The new record's ID is: " . $result; }
IsConnected() : boolean
boolean
TRUE idf connectect or FALSE if not connectedIsDateStr(string $value) : boolean
string
boolean
Returns TRUE if value is date or FALSE if not dateif (MySQL::IsDate("January 1, 2000")) { echo "valid date"; }
Kill(string $message, boolean $prepend_message)
string
The message to display on exit
boolean
(Optional) Whether the message should be shown as-is (FALSE) or followed by the last error message/description (TRUE) (Default: TRUE)
// Stop executing the script and show the last error $db->Kill();
MoveFirst() : boolean
boolean
Returns TRUE on success or FALSE on error$db->MoveFirst(); while (!$db->EndOfSeek()) { $row = $db->Row(); echo $row->ColumnName1 . " " . $row->ColumnName2 . "\n"; }
MoveLast() : boolean
boolean
Returns TRUE on success or FALSE on error$db->MoveLast();
Open(string $database, string $server, string $username, string $password, string $charset, string $collation, boolean $pcon) : boolean
string
(Optional) Database name
string
(Optional) Host address
string
(Optional) User name
string
(Optional) Password
string
(Optional) Character set
string
(Optional) Character set collation
boolean
(Optional) Persistant connection
boolean
Returns TRUE on success or FALSE on errorif (!$db->Open("MyDatabase", "localhost", "user", "password")) { $db->Kill(); }
Query(string $sql) : object
string
The query string should not end with a semicolon
object
PHP 'mysql result' resource object containing the records
on SELECT, SHOW, DESCRIBE or EXPLAIN queries and returns;
TRUE or FALSE for all others i.e. UPDATE, DELETE, DROP
AND FALSE on all errors (setting the local Error message).if (!$db->Query("SELECT * FROM Table")) echo $db->Kill();
QueryArray(string $sql, integer $resultType) : array
string
The query string should not end with a semicolon
integer
(Optional) The type of array Values can be: MYSQL_ASSOC, MYSQL_NUM, MYSQL_BOTH
array
A multi-dimensional array containing all the data
returned from the query or FALSE on all errorsQueryObjects(string $sql) : array
Executes the given SQL query and returns an array of objects, where each record is an object with the columns serving as object member variables.
string
The query string should not end with a semicolon
array
An array of record objects containing all the data
returned from the query or FALSE on all errorsQuerySingleRow(string $sql) : object
string
The query string should not end with a semicolon
object
PHP resource object containing the first row or
FALSE if no row is returned from the queryQuerySingleRowArray(string $sql, integer $resultType) : array
string
The query string should not end with a semicolon
integer
(Optional) The type of array Values can be: MYSQL_ASSOC, MYSQL_NUM, MYSQL_BOTH
array
An array containing the first row or FALSE if no row
is returned from the queryQuerySingleValue(string $sql) : mixed
If more than one row is returned, only the first value in the first column is returned.
string
The query string should not end with a semicolon
mixed
The value returned or FALSE if no valueQueryTimed(string $sql) : object
string
The query string should not end with a semicolon
object
PHP 'mysql result' resource object containing the records
on SELECT, SHOW, DESCRIBE or EXPLAIN queries and returns
TRUE or FALSE for all others i.e. UPDATE, DELETE, DROP.$db->QueryTimed("SELECT * FROM MyTable"); echo "Query took " . $db->TimerDuration() . " microseconds";
Records() : object
object
PHP 'mysql result' resource object containing the records
for the last query executed$records = $db->Records();
RecordsArray(integer $resultType) : array
Returns all records from the last query and returns the contents as an array of records where each record is presented as an array of columns (fields).
integer
(Optional) The type of array representing one record Values can be: MYSQL_ASSOC, MYSQL_NUM, MYSQL_BOTH. (Default: MYSQL_ASSOC)
array
Records in array form or FALSE on error. May return an
EMPTY array when no records are available.$myArray = $db->RecordsArray(MYSQL_ASSOC);
RecordsObjects() : array
Returns all records from the last query and returns the contents as an array of record objects (where each record is an object with each column as an attribute (data member variable)).
array
Records in object form or FALSE on error. May return an
EMPTY array when no records are available.Release(resource $result) : boolean
warning | It is an (non-fatal) error to Release() a query result more than once. |
---|
resource
(Optional) the result originally returned by any previous SQL query.
boolean
Returns TRUE on success or FALSE on failure$db->Release();
Row(integer $optional_row_number) : object
integer
(Optional) Use to specify a row
object
PHP object or FALSE on error$db->MoveFirst(); while (!$db->EndOfSeek()) { $row = $db->Row(); echo $row->ColumnName1 . " " . $row->ColumnName2 . "\n"; }
RowArray(integer $optional_row_number, integer $resultType) : array
integer
(Optional) Use to specify a row
integer
(Optional) The type of array Values can be: MYSQL_ASSOC, MYSQL_NUM, MYSQL_BOTH
array
Array that corresponds to the fetched row or FALSE on error or when no rows are available.for ($index = 0; $index < $db->RowCount(); $index++) { $val = $db->RowArray($index); }
RowCount() : integer
integer
Row count or FALSE on error$db->Query("SELECT * FROM Customer"); echo "Row Count: " . $db->RowCount();
SQLBooleanValue(mixed $value, mixed $trueValue, mixed $falseValue, string $datatype) : string
mixed
value to analyze for TRUE or FALSE
mixed
value to use if TRUE
mixed
value to use if FALSE
string
Use SQLVALUE constants or the strings: string, text, varchar, char, boolean, bool, Y-N, T-F, bit, date, datetime, time, integer, int, number, double, float
string
SQL formatted value of the specified data type on success or FALSE on errorecho MySQL::SQLBooleanValue(false, "1", "0", MySQL::SQLVALUE_NUMBER); echo MySQL::SQLBooleanValue($test, "Jan 1, 2007 ", "2007/06/01", MySQL::SQLVALUE_DATE); echo MySQL::SQLBooleanValue("ON", "Ya", "Nope"); echo MySQL::SQLBooleanValue(1, '+', '-');
SQLFix(string $value) : string
The returned string representing the $value will be properly escaped and filtered to use as part of a constructed SQL query.
string
string
SQL formatted value$value = MySQL::SQLFix("\hello\ /world/"); echo $value . "\n" . MySQL::SQLUnfix($value);
SQLUnfix(string $value) : string
warning | Do NOT use on columns returned by a database query: such data has already been adequately processed by MySQL itself. The only probable place where the SQLUnfix() method MAY be useful is when DIRECTLY accessing strings produced by the SQLValue() method. |
---|
string
string
$value = MySQL::SQLFix("\hello\ /world/"); echo $value . "\n" . MySQL::SQLUnfix($value);
SQLValue(mixed $value, string $datatype) : string
note | Also supports data types returned from the gettype function. |
---|
mixed
Any value of any type to be formatted to SQL
string
Use SQLVALUE constants or the strings: 'string', 'text', 'varchar', 'char', 'boolean', 'bool', 'Y-N', 'T-F', 'bit', 'date', 'datetime', 'time', 'integer', 'int', 'number', 'double', 'float'
string
The properly quoted and escaped/filtered value as a string
which can be safely included in a generated SQL query.echo MySQL::SQLValue("it's a string", "text"); $sql = "SELECT * FROM Table WHERE Field1 = " . MySQL::SQLValue("123", MySQL::SQLVALUE_NUMBER); $sql = "UPDATE Table SET Field1 = " . MySQL::SQLValue("July 4, 2007", MySQL::SQLVALUE_DATE);
Seek(integer $row_number) : object
integer
Row number
object
Fetched row as PHP object on success or FALSE on error$db->Seek(0); // Move to the first record
SeekPosition() : integer
integer
Current row numberecho "Current Row Cursor : " . $db->GetSeekPosition();
SelectArray(string $tableName, array | string $whereArray, array | string $columns, array | string $sortColumns, integer | string $limit, integer $resultType) : array
note | Any of the parameters $whereArray, $columns, $sortColumns or $limit may alternatively be a string, in which case these are used verbatim in the query. This is useful when advanced queries are constructed. |
---|
string
The name of the table
array
string
(Optional) An associative array containing the column names as keys and values as data. The values must be SQL ready (i.e. quotes around strings, formatted dates, etc.)
array
string
(Optional) The column or list of columns to select
array
string
(Optional) Column or list of columns to sort by. Column names may be prefixed by a plus(+) or minus(-) to indicate sort order. Default is ASCending for each column.
integer
string
(Optional) The limit of rows to return
integer
(Optional) The type of array Values can be: MYSQL_ASSOC, MYSQL_NUM, MYSQL_BOTH
array
A multi-dimensional array containing all the data
returned from the query or FALSE on all errorsSelectDatabase(string $database, string $charset) : boolean
string
Database name
string
(Optional) Character set, e.g. 'utf8'. (Default: NULL)
boolean
Returns TRUE on success or FALSE on error$db->SelectDatabase("DatabaseName");
SelectObjects(string $tableName, array | string $whereArray, array | string $columns, array | string $sortColumns, integer | string $limit) : array
note | Any of the parameters $whereArray, $columns, $sortColumns or $limit may alternatively be a string, in which case these are used verbatim in the query. This is useful when advanced queries are constructed. |
---|
string
The name of the table
array
string
(Optional) An associative array containing the column names as keys and values as data. The values must be SQL ready (i.e. quotes around strings, formatted dates, etc.)
array
string
(Optional) The column or list of columns to select
array
string
(Optional) Column or list of columns to sort by. Column names may be prefixed by a plus(+) or minus(-) to indicate sort order. Default is ASCending for each column.
integer
string
(Optional) The limit of rows to return
array
An array of record objects containing all the data
returned from the query or FALSE on all errorsSelectRows(string $tableName, array | string $whereArray, array | string $columns, array | string $sortColumns, integer | string $limit) : boolean
note | Any of the parameters $whereArray, $columns, $sortColumns or $limit may alternatively be a string, in which case these are used verbatim in the query. This is useful when advanced queries are constructed. |
---|
string
The name of the table
array
string
(Optional) An associative array containing the column names as keys and values as data. The values must be SQL ready (i.e. quotes around strings, formatted dates, etc.)
array
string
(Optional) The column or list of columns to select
array
string
(Optional) Column or list of columns to sort by. Column names may be prefixed by a plus(+) or minus(-) to indicate sort order. Default is ASCending for each column.
integer
string
(Optional) The limit of rows to return
boolean
Returns records on success or FALSE on error// $arrayVariable["column name"] = formatted SQL value $filter["Color"] = MySQL::SQLValue("Violet"); $filter["Age"] = MySQL::SQLValue(777, MySQL::SQLVALUE_NUMBER); // Execute the select $result = $db->SelectRows("MyTable", $filter); // If we have an error if (!$result) { // Show the error and kill the script $db->Kill(); }
SelectSingleRow(string $tableName, array | string $whereArray, array | string $columns, array | string $sortColumns, integer | string $limit) : object
note | Any of the parameters $whereArray, $columns, $sortColumns or $limit may alternatively be a string, in which case these are used verbatim in the query. This is useful when advanced queries are constructed. |
---|
string
The name of the table
array
string
(Optional) An associative array containing the column names as keys and values as data. The values must be SQL ready (i.e. quotes around strings, formatted dates, etc.)
array
string
(Optional) The column or list of columns to select
array
string
(Optional) Column or list of columns to sort by. Column names may be prefixed by a plus(+) or minus(-) to indicate sort order. Default is ASCending for each column.
integer
string
(Optional) The limit of rows to return
object
PHP resource object containing the first row or
FALSE if no row is returned from the querySelectSingleRowArray(string $tableName, array | string $whereArray, array | string $columns, array | string $sortColumns, integer | string $limit, integer $resultType) : array
note | Any of the parameters $whereArray, $columns, $sortColumns or $limit may alternatively be a string, in which case these are used verbatim in the query. This is useful when advanced queries are constructed. |
---|
string
The name of the table
array
string
(Optional) An associative array containing the column names as keys and values as data. The values must be SQL ready (i.e. quotes around strings, formatted dates, etc.)
array
string
(Optional) The column or list of columns to select
array
string
(Optional) Column or list of columns to sort by. Column names may be prefixed by a plus(+) or minus(-) to indicate sort order. Default is ASCending for each column.
integer
string
(Optional) The limit of rows to return
integer
(Optional) The type of array Values can be: MYSQL_ASSOC, MYSQL_NUM, MYSQL_BOTH
array
An array containing the first row or FALSE if no row
is returned from the querySelectSingleValue(string $tableName, array | string $whereArray, array | string $columns, array | string $sortColumns, integer | string $limit) : mixed
note | Any of the parameters $whereArray, $columns, $sortColumns or $limit may alternatively be a string, in which case these are used verbatim in the query. This is useful when advanced queries are constructed. |
---|
string
The name of the table
array
string
(Optional) An associative array containing the column names as keys and values as data. The values must be SQL ready (i.e. quotes around strings, formatted dates, etc.)
array
string
(Optional) The column or list of columns to select
array
string
(Optional) Column or list of columns to sort by. Column names may be prefixed by a plus(+) or minus(-) to indicate sort order. Default is ASCending for each column.
integer
string
(Optional) The limit of rows to return
mixed
The value returned or FALSE if no valueSelectTable(string $tableName) : boolean
string
The name of the table
boolean
Returns an array of records
(each an object where the columns are individual object member variables)
on success or FALSE on errorTimerDuration(integer $decimals) : Float
integer
(Optional) The number of decimal places to show (Default: 4)
Float
Microseconds elapsed$db->TimerStart(); // Do something or run some queries $db->TimerStop(); echo $db->TimerDuration(2) . " microseconds";
TimerStart()
$db->TimerStart(); // Do something or run some queries $db->TimerStop(); echo $db->TimerDuration() . " microseconds";
TimerStop()
$db->TimerStart(); // Do something or run some queries $db->TimerStop(); echo $db->TimerDuration() . " microseconds";
TransactionBegin() : boolean
boolean
Returns TRUE on success or FALSE on error$sql = "INSERT INTO MyTable (Field1, Field2) Values ('abc', 123)"; $db->TransactionBegin(); if ($db->Query($sql)) { $db->TransactionEnd(); echo "Last ID inserted was: " . $db->GetLastInsertID(); } else { $db->TransactionRollback(); echo "Query Failed"; }
TransactionEnd() : boolean
boolean
Returns TRUE on success or FALSE on error$sql = "INSERT INTO MyTable (Field1, Field2) Values ('abc', 123)"; $db->TransactionBegin(); if ($db->Query($sql)) { $db->TransactionEnd(); echo "Last ID inserted was: " . $db->GetLastInsertID(); } else { $db->TransactionRollback(); echo "Query Failed"; }
TransactionRollback() : boolean
boolean
Returns TRUE on success or FALSE on failure$sql = "INSERT INTO MyTable (Field1, Field2) Values ('abc', 123)"; $db->TransactionBegin(); if ($db->Query($sql)) { $db->TransactionEnd(); echo "Last ID inserted was: " . $db->GetLastInsertID(); } else { $db->TransactionRollback(); echo "Query Failed"; }
TruncateTable(string $tableName) : boolean
string
The name of the table
boolean
Returns TRUE on success or FALSE on errorUpdateRow(string $tableName, array $valuesArray, array | string $whereArray) : boolean
Updates rows in a table based on a WHERE filter (can be just one or many rows based on the filter).
string
The name of the table
array
An associative array containing the column names as keys and values as data. The values must be SQL ready (i.e. quotes around strings, formatted dates, etc.)
array
string
(Optional) An associative array containing the column names as keys and values as data. The values must be SQL ready (i.e. quotes around strings, formatted dates, etc.). If not specified then all values in the table are updated.
This parameter may alternatively be a string, in which case it is used verbatim for the WHERE clause of the query. This is useful when advanced queries are constructed.
boolean
Returns TRUE on success or FALSE on error// Create an array that holds the update information // $arrayVariable["column name"] = formatted SQL value $update["Name"] = MySQL::SQLValue("Bob"); $update["Age"] = MySQL::SQLValue(25, MySQL::SQLVALUE_NUMBER); // Execute the update where the ID is 1 if (!$db->UpdateRows("test", $values, array("id" => 1))) $db->Kill();
__construct(boolean $connect, string $database, string $server, string $username, string $password, string $charset, string $collation)
boolean
(Optional) Auto-connect when object is created
string
(Optional) Database name
string
(Optional) Host address
string
(Optional) User name
string
(Optional) Password
string
(Optional) Character set
string
(Optional) Character set collation
$db = new MySQL(); $db = new MySQL(true, "database"); $db = new MySQL(true, "database", "localhost", "username", "password");
__destruct()
BuildSQLColumns(array | string $columns, boolean $addQuotes, boolean $showAlias, boolean $withSortMarker) : string
This method can be used to construct a SELECT, FROM or SORT BY section of an SQL query.
array
string
Either an array containing the column names or a string. The latter is used when, for example, constructing 'advanced' queries with SUM(*) or other expressions in the SELECT fieldset section.
boolean
(Optional) TRUE to add quotes
boolean
(Optional) TRUE to show column alias
boolean
(Optional) TRUE when the field list is meant for an ORDER BY clause; fields may be prefixed by a plus(+) or minus(-) to indicate sort order. Default is ASCending for each field.
string
Returns the constructed SQL column list on success or NULL on failureResetError()
SetError(string $errorMessage, integer $errorNumber)
string
The error description
integer
The error number
$InDevelopmentEnvironment : boolean
Determines if the code is running in a development or production environment: error diagnostics information is far more elaborate in a development environment setting to aid problem analysis and resolution.
api |
---|
$ThrowExceptions : boolean
api |
---|
$active_row
$db_charset
utf8)
$db_charsetcollation
utf8_unicode_ci)
$db_dbname
$db_host
$db_pass
$db_pcon
$db_user
$error_desc
$error_number
$in_transaction
$last_insert_id
$last_result
$last_sql
$mysql_link
$query_count
$time_diff
$time_start
SQLVALUE_BIT
SQLVALUE_BOOLEAN
SQLVALUE_DATE
SQLVALUE_DATETIME
SQLVALUE_ENUMERATE
SQLVALUE_NUMBER
SQLVALUE_TEXT
SQLVALUE_TIME
SQLVALUE_T_F
SQLVALUE_Y_N