Class: SmartMysqliExtDb - provides a Dynamic (Extended) Client for MariaDB Server / MySQL that can be used with custom made connections.
This class is made to be used with custom made MySQLi connections (other servers than default).
Tested and Stable with MariaDB versions: 5.5.x / 10.x
Tested and Stable on MySQL versions: 5.5.x / 5.6.x / 5.7.x / 6.x / 7.x / 8.x
Language: PHP
Located at: lib/framework/plugins/lib_db_mysqli.php
Hints: This class have no catcheable Exception because the ONLY errors will raise are when the server returns an ERROR regarding a malformed SQL Statement, which is not acceptable to be just Exception, so will raise a fatal error !
Usage: dynamic object: (new Class())->method() - This class provides only DYNAMIC methods
@param: {ARRAY} $y_configs_arr: The Array of Configuration parameters - the ARRAY STRUCTURE should be identical with the default config.php: $configs['mysqli'].
Class Constructor - will initiate also the custom connection for a MariaDB Server / MySQL specified as parameters of this function.
publicfunctiongetConnection (
) {} ->
Returns the connection resource of the current MariaDB Server / MySQL.
@param: {STRING} $y_string: A String or a Number to be Quoted for LIKES
Fix a string to be compliant with MySQL LIKE / SIMILAR syntax.
It will use special quotes for the LIKE / SIMILAR special characters: % _
This function IS NOT INTENDED TO ESCAPE AGAINST SQL INJECTIONS ; USE IT ONLY WITH PREPARED PARAMS OR USE escape_str() with mode 'likes'
@return: {STRING} The Escaped String / Number
@param: {STRING} $y_string: A String or a Number to be Escaped
@param: {ENUM} $y_mode: '' = default ; 'likes' = Escape LIKE Syntax (% _)
Escape a string to be compliant and Safe (against SQL Injection) with MySQL standards.
This function WILL NOT ADD the SINGLE QUOTES (') arround the string, but just will just escape it to be safe.
@return: {INTEGER} the result of COUNT()
@param: {STRING} $queryval: the query
@param: {STRING} $params_or_title: *optional* array of parameters or query title for easy debugging
MySQL Query :: Count
This function is intended to be used for count type queries: SELECT COUNT().
@hints: ALWAYS use a LIMIT 1 OFFSET 0 with all queries using this function to avoid situations that will return more than 1 rows and will raise ERROR with this function.
@return: {ARRAY} (asociative) of results :: Returns just a SINGLE ROW as: array('column1' => 'val1', 'column2' => null, ... 'column-n' => 't')
@param: {STRING} $queryval: the query
@param: {STRING} $params_or_title: *optional* array of parameters or query title for easy debugging
MySQL Query :: Read (Associative) - Single Row (just for 1 row, to easy the use of data from queries).
!!! This will raise an error if more than one row(s) are returned !!!
This function does not support multiple rows because the associative data is structured without row iterator.
For queries that return more than one row use: read_adata() or read_data().
This function is intended to be used for read type queries: SELECT.
@return: {ARRAY} [ 0 => 'control-message', 1 => #affected-rows, 2 => #last-inserted-id(autoincrement)|0|null ]
@param: {STRING} $queryval: the query
@param: {STRING} $params_or_title: *optional* array of parameters or query title for easy debugging
MySQL Query :: Write.
This function is intended to be used for write type queries: BEGIN (TRANSACTION) ; COMMIT ; ROLLBACK ; INSERT ; INSERT IGNORE ; REPLACE ; UPDATE ; CREATE SCHEMAS ; CALLING STORED PROCEDURES ...
@return: {STRING} The SQL partial Statement
@param: {ARRAY} $arrdata: associative array: array of form data as $arr=array(); $arr['field1'] = 'a string'; $arr['field2'] = 100; | non-associative array $arr[] = 'some value'; $arr[] = 'other-value', ...
@param: {ENUM} $mode: mode: 'insert' | 'update' | 'in-select'
Create Escaped Write SQL Statements from Data - to be used with MySQL for: INSERT ; UPDATE ; IN-SELECT
Can be used with: write_data() to build INSERT / UPDATE queries from an associative array
or can be used with read_data(), read_adata(), read_asdata(), count_data() to build IN-SELECT queries from a non-associative array
@return: {STRING} The SQL processed (partial/full) Statement
@param: {STRING} $query: SQL Statement to process like ' WHERE ("id" = ?)'
@param: {ARRAY} $arrdata: The non-associative array as of: $arr=array('a');
Create Escaped SQL Statements from Parameters and Array of Data by replacing ? (question marks)
This can be used for a full SQL statement or just for a part.
The statement must not contain any Single Quotes to prevent SQL injections which are unpredictable if mixing several statements at once !
@return: {STRING} the generated Unique ID
@param: {ENUM} $y_mode: mode: uid10str | uid10num | uid10seq | uid12seq | uid32 | uid34 | uid36 | uid45
@param: {STRING} $y_field_name: the field name
@param: {STRING} $y_table_name: the table name
Get A UNIQUE (SAFE) ID for DB Tables
class Properties
class Constants
Sample code: PHP
<?php
// Sample config array for this class constructor: $custom_mysql = array(); $custom_mysql['type'] = 'mysql'; // mysql / mariadb / percona $custom_mysql['server-host'] = '127.0.0.1'; // database host (default is 127.0.0.1) $custom_mysql['server-port'] = '3306'; // database port (default is 3306) $custom_mysql['dbname'] = 'smart_framework'; // database name $custom_mysql['username'] = 'root'; // sql server user name $custom_mysql['password'] = base64_encode('root'); // sql server Base64-Encoded password for that user name B64 $custom_mysql['timeout'] = 30; // connection timeout (how many seconds to wait for a valid MySQL Connection) $custom_mysql['slowtime'] = 0.0050; // 0.0025 .. 0.0090 slow query time (for debugging) $custom_mysql['transact'] = 'REPEATABLE READ'; // Default Transaction Level: 'REPEATABLE READ' | 'READ COMMITTED' | '' to leave it as default // sample usage: $mysql = new SmartMysqliExtDb($custom_mysql); $mysql->read_adata('SELECT * FROM `my_table` LIMIT 100 OFFSET 0'); //... for other hints look to the samples of the class: SmartMysqliDb::*
// #end php code
documentation generated on: 2023-10-19 23:15:48 +0000
This class is made to be used with custom made MySQLi connections (other servers than default).
Tested and Stable with MariaDB versions: 5.5.x / 10.x
Tested and Stable on MySQL versions: 5.5.x / 5.6.x / 5.7.x / 6.x / 7.x / 8.x