# final class \SmartMysqliExtDb
{ } ->

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
- Package: Plugins:Database:MySQL
- Namespace: \
- Class Name: SmartMysqliExtDb
- Version: v.20221223
- Depends: extensions: PHP MySQLi ; classes: Smart, SmartEnvironment, SmartUnicode, SmartComponents (optional) ; constants: SMART_FRAMEWORK_SQL_CHARSET
- 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

## class Methods

public function __construct ( array $y_configs_arr ) {} @
@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.
public function getConnection ( ) {} ->
Returns the connection resource of the current MariaDB Server / MySQL.
public function quote_likes ( STRING $y_string ) {} ->
@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'
public function escape_str ( STRING $y_string, ENUM $y_mode = "" ) {} -> STRING
@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.
public function check_if_table_exists ( STRING $y_table ) {} -> 0/1
@return: {0/1} 1 if exists ; 0 if not
@param: {STRING} $y_table: The Table Name
Check if a Table Exists in the current Database.
public function count_data ( STRING $queryval, STRING $params_or_title = "" ) {} -> INTEGER
@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().
public function read_data ( STRING $queryval, STRING $params_or_title = "" ) {} -> ARRAY
@return: {ARRAY} (non-asociative) of results :: array('column-0-0', 'column-0-1', null, ..., 'column-0-n', 'column-1-0', 'column-1-1', ... 'column-1-n', ..., 'column-m-0', 'column-m-1', ..., 'column-m-n')
@param: {STRING} $queryval: the query
@param: {STRING} $params_or_title: *optional* array of parameters or query title for easy debugging
MySQL Query :: Read (Non-Associative) one or multiple rows.
This function is intended to be used for read type queries: SELECT.
public function read_adata ( STRING $queryval, STRING $params_or_title = "" ) {} -> ARRAY
@return: {ARRAY} (asociative) of results :: array(0 => array('column1' => 'val1', 'column2' => null, ... 'column-n' => 't'), 1 => array('column1' => 'val2', 'column2' => 'val2', ... 'column-n' => 'f'), ..., m => array('column1' => 'valM', 'column2' => 'xyz', ... '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) one or multiple rows.
This function is intended to be used for read type queries: SELECT.
public function read_asdata ( STRING $queryval, STRING $params_or_title = "" ) {} -> ARRAY
@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.
public function write_data ( STRING $queryval, STRING $params_or_title = "" ) {} -> ARRAY
@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 ...
public function prepare_statement ( ARRAY $arrdata, ENUM $mode ) {} -> STRING
@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
public function prepare_param_query ( STRING $query, ARRAY $arrdata ) {} -> STRING
@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 !
public function new_safe_id ( ENUM $y_mode, $y_id_field, STRING $y_table_name ) {} -> STRING
@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: 2024-12-16 16:53:45 +0000

Smart.Framework © 2009-2024 unix-world.org