Ultimate MySQL Class
Ultimate MySQL Class
Description
Description | Vars (details) | Methods (details) Constants (details)
1 of 25 5/13/2024, 10:29 AM
MySQL Ultimate Documentation file:///E:/UniServerZeroXV/www/vendor/ricci69/ultimatemysql/docs/in...
Jan 23, 2024 - Version 4.6 - Bug fixes provided by Paul Pazderski + PHP 8.3 compatible
include "mysql.class.php";
Usage (composer)
require "vendor/autoload.php";
$db = new MySQL();
$db = new MySQL(true, "database");
$db = new MySQL(true, "database", "localhost", "username", "password");
Debug mode
The script looks for a file called .debugmysql (within the root directory or within the composer's vendor / module
folder) and, if found, enters debug mode.
When debug mode is active, it writes all SQL queries executed inside the .debugmysql file.
SQLVALUE_BIT = "bit"
SQLVALUE_BOOLEAN = "boolean"
SQLVALUE_DATE = "date"
SQLVALUE_DATETIME = "datetime"
SQLVALUE_NUMBER = "number"
SQLVALUE_TEXT = "text"
SQLVALUE_TIME = "time"
SQLVALUE_T_F = "t-f"
SQLVALUE_Y_N = "y-n"
Variable Summary
Description | Vars (details) | Methods (details) Constants (details)
boolean $ThrowExceptions
Method Summary
Description | Constants (details) Vars (details) | Methods (details)
MySQL __construct ([boolean $connect = true], [string $database = ""], [string $server = ""], [string $username = ""],
[string $password = ""], [string $charset = ""])
2 of 25 5/13/2024, 10:29 AM
MySQL Ultimate Documentation file:///E:/UniServerZeroXV/www/vendor/ricci69/ultimatemysql/docs/in...
void __destruct ()
boolean AutoInsertUpdate (string $tableName, array $valuesArray, array $whereArray)
boolean BeginningOfSeek ()
string BuildSQLDelete (string $tableName, array $whereArray)
string BuildSQLInsert (string $tableName, array $valuesArray)
string BuildSQLSelect (string $tableName, [array $whereArray = null], [array/string $columns = null], [array/
string $sortColumns = null], [boolean $sortAscending = true], [integer/string $limit = null])
string BuildSQLUpdate (string $tableName, array $valuesArray, [array $whereArray = null])
string BuildSQLWhereClause (array $whereArray)
object Returns Close ()
boolean DeleteRows (string $tableName, [array $whereArray = null])
boolean EndOfSeek ()
string Error ()
integer ErrorNumber ()
boolean GetBooleanValue (any $value)
array GetColumnComments (string $table)
integer GetColumnCount ([string $table = ""])
string GetColumnDataType (string $column, [string $table = ""])
integer GetColumnID (string $column, [string $table = ""])
integer GetColumnLength (string $column, [string $table = ""])
integer GetColumnName (string $columnID, [string $table = ""])
array GetColumnNames ([string $table = ""])
string GetHTML ([boolean $showCount = true], [string $styleTable = null], [string $styleHeader = null], [string $styleData = null])
string GetJSON ()
integer GetLastInsertID ()
string GetLastSQL ()
array GetTables ()
boolean GetXML ()
string HasRecords ([string $sql = ""])
integer InsertRow (string $tableName, array $valuesArray)
boolean IsConnected ()
boolean IsDate (date/string $value)
void Kill ([mixed $message = ''])
boolean MoveFirst ()
boolean MoveLast ()
boolean Open ([string $database = ""], [string $server = ""], [string $username = ""], [string $password = ""], [string $charset = ""],
[boolean $pcon = false])
object PHP Query (string $sql)
array QueryArray (string $sql, [integer $resultType = MYSQL_BOTH])
object PHP QuerySingleRow (string $sql)
array QuerySingleRowArray (string $sql, [integer $resultType = MYSQL_BOTH])
mixed QuerySingleValue (string $sql)
object PHP QueryTimed (string $sql)
object PHP Records ()
Records RecordsArray ([integer $resultType = MYSQL_BOTH])
boolean Release ()
object PHP Row ([integer $optional_row_number = null])
array RowArray ([integer $optional_row_number = null], [integer $resultType = MYSQL_BOTH])
integer RowCount ()
object Fetched Seek (integer $row_number)
integer SeekPosition ()
boolean SelectDatabase (string $database, [string $charset = ""])
boolean SelectRows (string $tableName, [array $whereArray = null], [array/string $columns = null], [array/string $sortColumns =
null], [boolean $sortAscending = true], [integer/string $limit = null])
boolean SelectTable (string $tableName)
string SQLBooleanValue (any $value, any $trueValue, any $falseValue, [string $datatype = self::SQLVALUE_TEXT])
string SQLFix (string $value)
string SQLUnfix (string $value)
string SQLValue (any $value, [string $datatype = self::SQLVALUE_TEXT])
Float TimerDuration ([integer $decimals = 4])
void TimerStart ()
3 of 25 5/13/2024, 10:29 AM
MySQL Ultimate Documentation file:///E:/UniServerZeroXV/www/vendor/ricci69/ultimatemysql/docs/in...
void TimerStop ()
boolean TransactionBegin ()
boolean TransactionEnd ()
boolean TransactionRollback ()
boolean TruncateTable (string $tableName)
boolean UpdateRows (string $tableName, array $valuesArray, [array $whereArray = null])
Variables
Description | Vars (details) Constants (details) | Methods (details)
Methods
Description | Vars (details) Constants (details) Methods (details)
Constructor __construct
access: public
MySQL __construct ([boolean $connect = true], [string $database = ""], [string $server = ""], [string $username = ""],
[string $password = ""], [string $charset = ""])
Example:
Destructor __destruct
access: public
void __destruct ()
4 of 25 5/13/2024, 10:29 AM
MySQL Ultimate Documentation file:///E:/UniServerZeroXV/www/vendor/ricci69/ultimatemysql/docs/in...
BeginningOfSeek
boolean BeginningOfSeek ()
Example:
if ($db->BeginningOfSeek()) {
echo "We are at the beggining of the record set";
}
BuildSQLDelete
BuildSQLInsert
5 of 25 5/13/2024, 10:29 AM
MySQL Ultimate Documentation file:///E:/UniServerZeroXV/www/vendor/ricci69/ultimatemysql/docs/in...
BuildSQLSelect
string BuildSQLSelect (string $tableName, [array $whereArray = null], [array/string $columns = null], [array/
string $sortColumns = null], [boolean $sortAscending = true], [integer/string $limit = null])
BuildSQLUpdate
6 of 25 5/13/2024, 10:29 AM
MySQL Ultimate Documentation file:///E:/UniServerZeroXV/www/vendor/ricci69/ultimatemysql/docs/in...
BuildSQLWhereClause
[STATIC] Builds a SQL WHERE clause from an array. 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 $whereArray: 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, ect)
Close
Example:
$db->Close();
DeleteRows
Deletes rows in a table based on a WHERE filter (can be just one or many rows based on the filter)
7 of 25 5/13/2024, 10:29 AM
MySQL Ultimate Documentation file:///E:/UniServerZeroXV/www/vendor/ricci69/ultimatemysql/docs/in...
as data. The values must be SQL ready (i.e. quotes around strings, formatted dates, ect). If not specified
then all values in the table are deleted.
Example
// If we have an error
if (! $result) {
EndOfSeek
boolean EndOfSeek ()
Example:
if ($db->EndOfSeek()) {
echo "We are at the end of the record set";
}
Error
return: Error text from last known error or FALSE if no errors happened
access: public
string Error ()
Example:
if ($db->Error()) $db->Kill();
ErrorNumber
8 of 25 5/13/2024, 10:29 AM
MySQL Ultimate Documentation file:///E:/UniServerZeroXV/www/vendor/ricci69/ultimatemysql/docs/in...
return: Error number from last known error or FALSE if no errors happened
access: public
integer ErrorNumber ()
Example:
if ($db->ErrorNumber() <> 0) {
$db->Kill(); //show the error message
}
GetBooleanValue
[STATIC] Converts any value of any datatype into boolean (true or false)
Example:
GetColumnComments
Returns the comments for fields in a table into an array or returns FALSE on error
Example:
$columns = $db->GetColumnComments("MyTable");
foreach ($columns as $column => $comment) {
echo $column . " = " . $comment . "<br />\n";
}
9 of 25 5/13/2024, 10:29 AM
MySQL Ultimate Documentation file:///E:/UniServerZeroXV/www/vendor/ricci69/ultimatemysql/docs/in...
GetColumnCount
string $table: (Optional) If a table name is not specified, the column count is returned from the last query
Example:
GetColumnDataType
This function returns the data type for a specified column. If the column does not exists or no
records exist, it returns FALSE
Example:
GetColumnID
return: Column ID
access: public
Example:
GetColumnLength
10 of 25 5/13/2024, 10:29 AM
MySQL Ultimate Documentation file:///E:/UniServerZeroXV/www/vendor/ricci69/ultimatemysql/docs/in...
Example:
GetColumnName
This function returns the name for a specified column number. If the index does not exists or no
records exist, it returns FALSE
Example:
GetColumnNames
Returns the field names in a table in an array or NULL if the table has no fields
string $table: (Optional) If a table name is not specified, the last returned records are used
Example:
$columns = $db->GetColumnNames("MyTable");
foreach ($columns as $columnName) {
echo $columnName . "<br />\n";
}
GetHTML
string GetHTML ([boolean $showCount = true], [string $styleTable = null], [string $styleHeader = null], [string $styleData
= null])
boolean $showCount: (Optional) TRUE if you want to show the row count, FALSE if you do not want to
11 of 25 5/13/2024, 10:29 AM
MySQL Ultimate Documentation file:///E:/UniServerZeroXV/www/vendor/ricci69/ultimatemysql/docs/in...
Example:
GetJSON
string GetJSON ()
GetLastInsertID
integer GetLastInsertID ()
Example:
GetLastSQL
string GetLastSQL ()
Example:
GetTables
12 of 25 5/13/2024, 10:29 AM
MySQL Ultimate Documentation file:///E:/UniServerZeroXV/www/vendor/ricci69/ultimatemysql/docs/in...
This function returns table names from the database into an array. If the database does not
contains any tables, the returned value is FALSE
array GetTables ()
Example:
$tables = $db->GetTables();
foreach ($tables as $table) {
echo $table . "<br />\n";
}
GetXML
string GetXML ()
string $sql: [Optional] If specified, the query is first executed Otherwise, the last query is used for
comparison
InsertRow
Example
13 of 25 5/13/2024, 10:29 AM
MySQL Ultimate Documentation file:///E:/UniServerZeroXV/www/vendor/ricci69/ultimatemysql/docs/in...
// If we have an error
if (! $result) {
} else {
IsDate
[STATIC] Determines if a value of any data type is a date PHP can convert
date/string $value
Example
if (MySQL::IsDate("January 1, 2000")) {
echo "valid date";
}
Kill
Stop executing (die/exit) and show the last MySQL error message
access: public
Example:
MoveFirst
14 of 25 5/13/2024, 10:29 AM
MySQL Ultimate Documentation file:///E:/UniServerZeroXV/www/vendor/ricci69/ultimatemysql/docs/in...
boolean MoveFirst ()
Example:
$db->MoveFirst();
while (! $db->EndOfSeek()) {
$row = $db->Row();
echo $row->ColumnName1 . " " . $row->ColumnName2 . "\n";
}
MoveLast
boolean MoveLast ()
Example:
$db->MoveLast();
Open
boolean Open ([string $database = ""], [string $server = ""], [string $username = ""], [string $password = ""],
[string $charset = ""], [boolean $pcon = false])
Example
Query
return: '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)
15 of 25 5/13/2024, 10:29 AM
MySQL Ultimate Documentation file:///E:/UniServerZeroXV/www/vendor/ricci69/ultimatemysql/docs/in...
access: public
string $sql: The query string should not end with a semicolon
Example:
return: A multi-dimensional array containing all the data returned from the query or FALSE on all errors
access: public
string $sql: The query string should not end with a semicolon
integer $resultType: (Optional) The type of array Values can be: MYSQL_ASSOC, MYSQL_NUM,
MYSQL_BOTH
Executes the given SQL query and returns only one (the first) row
return: resource object containing the first row or FALSE if no row is returned from the query
access: public
string $sql: The query string should not end with a semicolon
Executes the given SQL query and returns the first row as an array
return: An array containing the first row or FALSE if no row is returned from the query
access: public
string $sql: The query string should not end with a semicolon
integer $resultType: (Optional) The type of array Values can be: MYSQL_ASSOC, MYSQL_NUM,
MYSQL_BOTH
Executes a query and returns a single value. If more than one row is returned, only the first value
in the first column is returned.
16 of 25 5/13/2024, 10:29 AM
MySQL Ultimate Documentation file:///E:/UniServerZeroXV/www/vendor/ricci69/ultimatemysql/docs/in...
access: public
string $sql: The query string should not end with a semicolon
QueryTimed
Executes the given SQL query, measures it, and saves the total duration in microseconds
return: '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
access: public
string $sql: The query string should not end with a semicolon
Example
Records
return: '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
access: public
Example:
$records = $db->Records();
RecordsArray
Returns all records from last query and returns contents as array or FALSE on error
integer $resultType: (Optional) The type of array Values can be: MYSQL_ASSOC, MYSQL_NUM,
MYSQL_BOTH
Example
$myArray = $db->RecordsArray(MYSQL_ASSOC);
17 of 25 5/13/2024, 10:29 AM
MySQL Ultimate Documentation file:///E:/UniServerZeroXV/www/vendor/ricci69/ultimatemysql/docs/in...
Release
Frees memory used by the query results and returns the function result
boolean Release ()
Example:
$db->Release();
Row
Reads the current row and returns contents as a PHP object or returns false on error
Example:
$db->MoveFirst();
while (! $db->EndOfSeek()) {
$row = $db->Row();
echo $row->ColumnName1 . " " . $row->ColumnName2 . "\n";
}
RowArray
Reads the current row and returns contents as an array or returns false on error
Example:
RowCount
18 of 25 5/13/2024, 10:29 AM
MySQL Ultimate Documentation file:///E:/UniServerZeroXV/www/vendor/ricci69/ultimatemysql/docs/in...
integer RowCount ()
Example:
Seek
Sets the internal database pointer to the specified row number and returns the result
Example:
SeekPosition
integer SeekPosition ()
Example:
SelectDatabase
Example:
$db->SelectDatabase("DatabaseName");
19 of 25 5/13/2024, 10:29 AM
MySQL Ultimate Documentation file:///E:/UniServerZeroXV/www/vendor/ricci69/ultimatemysql/docs/in...
SelectRows
boolean SelectRows (string $tableName, [array $whereArray = null], [array/string $columns = null], [array/
string $sortColumns = null], [boolean $sortAscending = true], [integer/string $limit = null])
Example
// If we have an error
if (! $result) {
SQLBooleanValue
20 of 25 5/13/2024, 10:29 AM
MySQL Ultimate Documentation file:///E:/UniServerZeroXV/www/vendor/ricci69/ultimatemysql/docs/in...
static
string SQLBooleanValue (any $value, any $trueValue, any $falseValue, [string $datatype = 'string'])
Example:
SQLFix
string $value
Example:
SQLUnfix
access: public
static
string $value
Example:
SQLValue
21 of 25 5/13/2024, 10:29 AM
MySQL Ultimate Documentation file:///E:/UniServerZeroXV/www/vendor/ricci69/ultimatemysql/docs/in...
[STATIC] Formats any value into a string suitable for SQL statements (NOTE: Also supports data
types returned from the gettype function)
access: public
static
Example:
TimerDuration
Example:
$db->TimerStart();
// Do something or run some queries
$db->TimerStop();
echo $db->TimerDuration(2) . " microseconds";
TimerStart
access: public
void TimerStart ()
Example:
$db->TimerStart();
// Do something or run some queries
$db->TimerStop();
echo $db->TimerDuration() . " microseconds";
22 of 25 5/13/2024, 10:29 AM
MySQL Ultimate Documentation file:///E:/UniServerZeroXV/www/vendor/ricci69/ultimatemysql/docs/in...
TimerStop
access: public
void TimerStop ()
Example:
$db->TimerStart();
// Do something or run some queries
$db->TimerStop();
echo $db->TimerDuration() . " microseconds";
TransactionBegin
Starts a transaction
boolean TransactionBegin ()
Example:
TransactionEnd
boolean TransactionEnd ()
Example:
23 of 25 5/13/2024, 10:29 AM
MySQL Ultimate Documentation file:///E:/UniServerZeroXV/www/vendor/ricci69/ultimatemysql/docs/in...
TransactionRollback
boolean TransactionRollback ()
Example:
UpdateRows
24 of 25 5/13/2024, 10:29 AM
MySQL Ultimate Documentation file:///E:/UniServerZeroXV/www/vendor/ricci69/ultimatemysql/docs/in...
SQLVALUE_BIT = "bit"
SQLVALUE_BOOLEAN = "boolean"
SQLVALUE_DATE = "date"
SQLVALUE_DATETIME = "datetime"
SQLVALUE_NUMBER = "number"
SQLVALUE_TEXT = "text"
SQLVALUE_TIME = "time"
SQLVALUE_T_F = "t-f"
SQLVALUE_Y_N = "y-n"
25 of 25 5/13/2024, 10:29 AM