IDBMS
in
Interface for a generic Database Management System.
It also defines shared constants to prevent circular dependencies.
Table of Contents
Constants
- ALERT = 1
- CRITICAL = 2
- DB_ASSOC = 0
- DB_BOTH = 2
- DB_NUM = 1
- DEBUG = 7
- EMERGENCY = 0
- ERROR = 3
- INFO = 6
- NOTICE = 5
- REGEX_BIT = '/^[0-1]+$/'
- REGEX_DATE = '/^\d{4}\-\d{2}\-\d{2}$/'
- REGEX_DATETIME = '/\d{4}\-\d{2}\-\d{2}\s{1}\d{2}:\d{2}[:\d{2}]?/'
- REGEX_EMAIL = '/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)/i'
- REGEX_INDEXES = '/[\d,]+/'
- REGEX_INT = '/^[-]?[\d]+$/'
- REGEX_NULL_BIT = '/^[0-1]+|$/'
- REGEX_NULL_DATE = '/^\d{4}\-\d{2}\-\d{2}|$/'
- REGEX_NULL_DATETIME = '/\d{4}\-\d{2}\-\d{2}\s{1}\d{2}:\d{2}[:\d{2}]?|$/'
- REGEX_NULL_EMAIL = '/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)|/i'
- REGEX_NULL_INDEXES = '/[\d,]+|/'
- REGEX_NULL_INT = '/^[-]?[\d]+|$/'
- REGEX_NULL_NUMBER = '/^\-?\d*\.?\d*|$/'
- REGEX_NULL_PHONE = '/^[+][0-9\s\.]|$/'
- REGEX_NULL_TIME = '/^\d{2}:\d{2}[:\d{2}]?|$/'
- REGEX_NULL_TIMESTAMP = '/^[\d]{10}|$/'
- REGEX_NULL_UINT = '/^[\d]+|$/'
- REGEX_NULL_URL = '/^(http|https?:\/\/(?:www\.|(?!www))[^\s\.]+\.[^\s]{2,3}|www\.[^\s]+\.[^\s]{2,3})|$/'
- REGEX_NULL_YEAR = '/^\d{4}|$/'
- REGEX_NUMBER = '/^\-?\d*\.?\d*$/'
- REGEX_PHONE = '/^[+][0-9\s\.]/'
- REGEX_TIME = '/^\d{2}:\d{2}[:\d{2}]?$/'
- REGEX_TIMESTAMP = '/^[\d]{10}$/'
- REGEX_UINT = '/^[\d]+$/'
- REGEX_URL = '/^(http|https?:\/\/(?:www\.|(?!www))[^\s\.]+\.[^\s]{2,3}|www\.[^\s]+\.[^\s]{2,3})$/'
- REGEX_YEAR = '/^\d{4}$/'
- WARNING = 4
Methods
- BeginTransaction() : void
- Starts a DB transaction.
- Commit() : void
- Commits the current transaction.
- ConvertDBType2BindType() : string
- Converts a generic DB data type into a driver-specific bind type.
- Decrypt() : string
- Returns the DB instruction to decrypt a value.
- DeleteRecord() : bool
- Delete records from a DB table
- Disconnect() : void
- Releases the resource to connect to the DB
- DisconnectAll() : void
- Releases all the resources of the previously opened DBs
- Encrypt() : string
- Returns the DB instruction to encrypt a value.
- Execute() : void
- Executes a previously prepared statement.
- ExistsTable() : bool
- Checks if a table exists in the database.
- ExistsTableColumns() : bool
- Checks if a list of columns exists in a table.
- GetAffectedRows() : int
- Returns how many rows were affected by the last operation performed.
- GetAttributesFromType() : bool
- Gets field attributes based on a DB data type.
- GetColumnNames() : array<string|int, string>|null
- Returns an array containing the names of all columns for the last query executed.
- GetDataTable() : int|null
- Fetches the entire result set of a query into an array.
- GetDataValue() : string|null
- Returns a single value from a query result.
- GetDBResultAssoc() : int
- Returns the driver-specific value for an associative array fetch type.
- GetDBResultBoth() : int
- Returns the driver-specific value for a fetch type that includes both associative and numeric arrays.
- GetDBResultNum() : int
- Returns the driver-specific value for a numeric array fetch type.
- GetDBTable() : string
- Returns the name of the current main table
- GetFetchArray() : array<string|int, mixed>|null
- Fetches a result row as an array (both numeric and associative).
- GetFetchAssoc() : array<string|int, mixed>|null
- Fetches a result row as an associative array.
- GetFetchRow() : array<string|int, mixed>|null
- Fetches a result row as a numeric array.
- GetLastDBErrorNumber() : int
- Gets any error number issued by the DB.
- GetLastDBErrorString() : string
- Gets any error string issued by the DB.
- GetLastID() : int|null
- Returns the ID of the last inserted item
- GetNextID() : int|null
- Returns the next ID from a sequence or similar.
- GetTableColumnNames() : array<string|int, string>
- Returns an array containing the names of all columns of a table.
- GetTotalColumns() : int|bool
- Returns the number of columns of a previously executed query.
- GetTotalRows() : int|bool
- Reads the total number of rows from a previously executed query.
- InsertRecord() : bool
- Make an entry in the DB
- InsertRecordBatch() : bool
- Insert multiple records in a single batch operation
- LoadAllTables() : void
- Loads the schema of all tables into an array.
- Prepare() : void
- Prepares an SQL statement for execution.
- Query() : bool
- Executes a query on the DB.
- Rollback() : void
- Rolls back the current transaction.
- SetAutoCommit() : void
- Sets the autocommit mode.
- SetDBColumns() : void
- Loads the schema of a table's columns into an array.
- SetDBTable() : void
- Sets the name of the reference table for the instance.
- UpdateRecord() : bool
- Make an update in the DB
Constants
ALERT
public
int
ALERT
= 1
Log level for alerts.
CRITICAL
public
int
CRITICAL
= 2
Log level for critical conditions.
DB_ASSOC
public
int
DB_ASSOC
= 0
Generic fetch type for an associative array.
DB_BOTH
public
int
DB_BOTH
= 2
Generic fetch type for both associative and numeric array.
DB_NUM
public
int
DB_NUM
= 1
Generic fetch type for a numeric array.
DEBUG
public
int
DEBUG
= 7
Log level for debug messages.
EMERGENCY
public
int
EMERGENCY
= 0
Log level for emergencies.
ERROR
public
int
ERROR
= 3
Log level for errors.
INFO
public
int
INFO
= 6
Log level for informational messages.
NOTICE
public
int
NOTICE
= 5
Log level for notices.
REGEX_BIT
public
string
REGEX_BIT
= '/^[0-1]+$/'
REGEX for bit values
REGEX_DATE
public
string
REGEX_DATE
= '/^\d{4}\-\d{2}\-\d{2}$/'
REGEX for date values
REGEX_DATETIME
public
string
REGEX_DATETIME
= '/\d{4}\-\d{2}\-\d{2}\s{1}\d{2}:\d{2}[:\d{2}]?/'
REGEX for datetime values
REGEX_EMAIL
public
string
REGEX_EMAIL
= '/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)/i'
REGEX for emails
REGEX_INDEXES
public
string
REGEX_INDEXES
= '/[\d,]+/'
REGEX for comma-separated indexes
REGEX_INT
public
string
REGEX_INT
= '/^[-]?[\d]+$/'
REGEX for integers
REGEX_NULL_BIT
public
string
REGEX_NULL_BIT
= '/^[0-1]+|$/'
REGEX for optional bit values
REGEX_NULL_DATE
public
string
REGEX_NULL_DATE
= '/^\d{4}\-\d{2}\-\d{2}|$/'
REGEX for optional date values
REGEX_NULL_DATETIME
public
string
REGEX_NULL_DATETIME
= '/\d{4}\-\d{2}\-\d{2}\s{1}\d{2}:\d{2}[:\d{2}]?|$/'
REGEX for optional datetime values
REGEX_NULL_EMAIL
public
string
REGEX_NULL_EMAIL
= '/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)|/i'
REGEX for optional emails
REGEX_NULL_INDEXES
public
string
REGEX_NULL_INDEXES
= '/[\d,]+|/'
REGEX for optional comma-separated indexes
REGEX_NULL_INT
public
string
REGEX_NULL_INT
= '/^[-]?[\d]+|$/'
REGEX for optional integers
REGEX_NULL_NUMBER
public
string
REGEX_NULL_NUMBER
= '/^\-?\d*\.?\d*|$/'
REGEX for optional numbers
REGEX_NULL_PHONE
public
string
REGEX_NULL_PHONE
= '/^[+][0-9\s\.]|$/'
REGEX for optional phone numbers
REGEX_NULL_TIME
public
string
REGEX_NULL_TIME
= '/^\d{2}:\d{2}[:\d{2}]?|$/'
REGEX for optional time values
REGEX_NULL_TIMESTAMP
public
string
REGEX_NULL_TIMESTAMP
= '/^[\d]{10}|$/'
REGEX for optional timestamps
REGEX_NULL_UINT
public
string
REGEX_NULL_UINT
= '/^[\d]+|$/'
REGEX for optional unsigned integers
REGEX_NULL_URL
public
string
REGEX_NULL_URL
= '/^(http|https?:\/\/(?:www\.|(?!www))[^\s\.]+\.[^\s]{2,3}|www\.[^\s]+\.[^\s]{2,3})|$/'
REGEX for optional URLs
REGEX_NULL_YEAR
public
string
REGEX_NULL_YEAR
= '/^\d{4}|$/'
REGEX for optional year values
REGEX_NUMBER
public
string
REGEX_NUMBER
= '/^\-?\d*\.?\d*$/'
REGEX for numbers
REGEX_PHONE
public
string
REGEX_PHONE
= '/^[+][0-9\s\.]/'
REGEX for phone numbers
REGEX_TIME
public
string
REGEX_TIME
= '/^\d{2}:\d{2}[:\d{2}]?$/'
REGEX for time values
REGEX_TIMESTAMP
public
string
REGEX_TIMESTAMP
= '/^[\d]{10}$/'
REGEX for timestamps
REGEX_UINT
public
string
REGEX_UINT
= '/^[\d]+$/'
REGEX for unsigned integers
REGEX_URL
public
string
REGEX_URL
= '/^(http|https?:\/\/(?:www\.|(?!www))[^\s\.]+\.[^\s]{2,3}|www\.[^\s]+\.[^\s]{2,3})$/'
REGEX for URLs
REGEX_YEAR
public
string
REGEX_YEAR
= '/^\d{4}$/'
REGEX for year values
WARNING
public
int
WARNING
= 4
Log level for warnings.
Methods
BeginTransaction()
Starts a DB transaction.
public
BeginTransaction() : void
Commit()
Commits the current transaction.
public
Commit() : void
ConvertDBType2BindType()
Converts a generic DB data type into a driver-specific bind type.
public
ConvertDBType2BindType(string|null $db_type) : string
Parameters
- $db_type : string|null
-
The DB data type.
Return values
string —The corresponding variable type for parameter binding.
Decrypt()
Returns the DB instruction to decrypt a value.
public
Decrypt(string $val[, string $name = '' ]) : string
Parameters
- $val : string
-
value or field name to decrypt
- $name : string = ''
-
alias for the returned field
Return values
string —DB instruction to decrypt $val
DeleteRecord()
Delete records from a DB table
public
DeleteRecord(string|null $table, string $conditions, array<string|int, string> $conditions_values, array<string|int, string> $types) : bool
Parameters
- $table : string|null
-
name of the table
- $conditions : string
-
of the where clause
- $conditions_values : array<string|int, string>
-
values present in the WHERE condition
- $types : array<string|int, string>
-
of DB table fields
Return values
bool —result of the operation, true if successful
Disconnect()
Releases the resource to connect to the DB
public
static Disconnect([string|null $dbkey = null ]) : void
Parameters
- $dbkey : string|null = null
-
key of db to disconnect (optional)
DisconnectAll()
Releases all the resources of the previously opened DBs
public
static DisconnectAll() : void
Encrypt()
Returns the DB instruction to encrypt a value.
public
Encrypt(string $val[, string $name = '' ]) : string
Parameters
- $val : string
-
value or field name to be encrypted
- $name : string = ''
-
alias for the returned field
Return values
string —DB instruction to encrypt $val
Execute()
Executes a previously prepared statement.
public
Execute([array<string|int, mixed> $bind_param_values = [] ][, array<string|int, string> $bind_param_types = [] ]) : void
Parameters
- $bind_param_values : array<string|int, mixed> = []
- $bind_param_types : array<string|int, string> = []
ExistsTable()
Checks if a table exists in the database.
public
ExistsTable(string $table) : bool
Parameters
- $table : string
-
name of the table
Return values
bool —true if it exists, false if it does not
ExistsTableColumns()
Checks if a list of columns exists in a table.
public
ExistsTableColumns(string|null $table, array<string|int, string> $names) : bool
Parameters
- $table : string|null
-
name of table
- $names : array<string|int, string>
-
list of field names to check
Return values
bool —true if all fields exist
GetAffectedRows()
Returns how many rows were affected by the last operation performed.
public
GetAffectedRows() : int
Return values
int —total of rows affected by the last operation
GetAttributesFromType()
Gets field attributes based on a DB data type.
public
GetAttributesFromType(string $type, array<string, mixed> &$values) : bool
Parameters
- $type : string
-
the db type to check (e.g., INT, VARCHAR)
- $values : array<string, mixed>
-
container for the attributes
Return values
bool —true if attributes were found
GetColumnNames()
Returns an array containing the names of all columns for the last query executed.
public
GetColumnNames() : array<string|int, string>|null
Return values
array<string|int, string>|null —the associative array of column names
GetDataTable()
Fetches the entire result set of a query into an array.
public
GetDataTable(array<string|int, mixed> &$data[, int|null $type = null ][, string|null $with_index = null ]) : int|null
Parameters
- $data : array<string|int, mixed>
-
array containing the records found
- $type : int|null = null
-
the fetch type (e.g., IDBMS::DB_ASSOC)
- $with_index : string|null = null
-
field name to use as the index of the main array
Return values
int|null —the total of records found or null on error
GetDataValue()
Returns a single value from a query result.
public
GetDataValue([int|string $name_col = '0' ][, int|null $pos_row = null ]) : string|null
Parameters
- $name_col : int|string = '0'
-
column name or numeric index
- $pos_row : int|null = null
-
position of the row
Return values
string|null —value of the indicated cell, or null if it does not exist
GetDBResultAssoc()
Returns the driver-specific value for an associative array fetch type.
public
GetDBResultAssoc() : int
Return values
intGetDBResultBoth()
Returns the driver-specific value for a fetch type that includes both associative and numeric arrays.
public
GetDBResultBoth() : int
Return values
intGetDBResultNum()
Returns the driver-specific value for a numeric array fetch type.
public
GetDBResultNum() : int
Return values
intGetDBTable()
Returns the name of the current main table
public
GetDBTable() : string
Return values
string —name of the main reference table
GetFetchArray()
Fetches a result row as an array (both numeric and associative).
public
GetFetchArray([int|null $pos_row = null ]) : array<string|int, mixed>|null
Parameters
- $pos_row : int|null = null
-
position of the row to read
Return values
array<string|int, mixed>|null —the fetched row
GetFetchAssoc()
Fetches a result row as an associative array.
public
GetFetchAssoc([int|null $pos_row = null ]) : array<string|int, mixed>|null
Parameters
- $pos_row : int|null = null
-
position of the row to read
Return values
array<string|int, mixed>|null —the fetched row
GetFetchRow()
Fetches a result row as a numeric array.
public
GetFetchRow([int|null $pos_row = null ]) : array<string|int, mixed>|null
Parameters
- $pos_row : int|null = null
-
position of the row to read
Return values
array<string|int, mixed>|null —the fetched row
GetLastDBErrorNumber()
Gets any error number issued by the DB.
public
static GetLastDBErrorNumber() : int
Return values
int —integer value containing the error issued by the DB
GetLastDBErrorString()
Gets any error string issued by the DB.
public
static GetLastDBErrorString() : string
Return values
string —containing the error issued by the DB
GetLastID()
Returns the ID of the last inserted item
public
GetLastID() : int|null
Return values
int|null —The ID of the last inserted element, or null on failure.
GetNextID()
Returns the next ID from a sequence or similar.
public
GetNextID([string $table = '' ]) : int|null
Parameters
- $table : string = ''
-
the name of counter associated to SEQUENCE
Return values
int|null —the next ID of the table
GetTableColumnNames()
Returns an array containing the names of all columns of a table.
public
GetTableColumnNames(string $tablename) : array<string|int, string>
Parameters
- $tablename : string
-
name of table
Return values
array<string|int, string> —an array with all field names
GetTotalColumns()
Returns the number of columns of a previously executed query.
public
GetTotalColumns() : int|bool
Return values
int|bool —total of the columns or false on error
GetTotalRows()
Reads the total number of rows from a previously executed query.
public
GetTotalRows() : int|bool
Return values
int|bool —total number of rows or false on error
InsertRecord()
Make an entry in the DB
public
InsertRecord(string|null $table, array<string, mixed> $items, array<string|int, string> $types) : bool
Parameters
- $table : string|null
-
name of the table
- $items : array<string, mixed>
-
associative array FIELD_NAME => FIELD_VALUE
- $types : array<string|int, string>
-
of DB table fields
Return values
bool —true if the insertion has been made
InsertRecordBatch()
Insert multiple records in a single batch operation
public
InsertRecordBatch(string|null $table, array<string, mixed> $items, array<string|int, array<string, mixed>> $batch_data, array<string|int, string> $types) : bool
Parameters
- $table : string|null
-
name of the table (if null uses the default table)
- $items : array<string, mixed>
-
associative array with field names as keys for the first record
- $batch_data : array<string|int, array<string, mixed>>
-
array of arrays, each containing values for one record
- $types : array<string|int, string>
-
list of types mapped one to one with fields
Return values
bool —true if successful, false otherwise
LoadAllTables()
Loads the schema of all tables into an array.
public
LoadAllTables(array<string, mixed> &$db_tables) : void
Parameters
- $db_tables : array<string, mixed>
-
list of tables to be returned
Prepare()
Prepares an SQL statement for execution.
public
Prepare(string $sql) : void
Parameters
- $sql : string
-
string containing the query to prepare
Query()
Executes a query on the DB.
public
Query(string $sql[, array<string|int, mixed> $bind_param_values = [] ][, array<string|int, string> $bind_param_types = [] ]) : bool
Parameters
- $sql : string
-
string containing the query to execute
- $bind_param_values : array<string|int, mixed> = []
-
deferred values for the query
- $bind_param_types : array<string|int, string> = []
-
DB data types
Return values
bool —true if the query was successful
Rollback()
Rolls back the current transaction.
public
Rollback() : void
SetAutoCommit()
Sets the autocommit mode.
public
SetAutoCommit([bool $bool = true ]) : void
Parameters
- $bool : bool = true
-
if is true the autocommit is running
SetDBColumns()
Loads the schema of a table's columns into an array.
public
SetDBColumns(array<string|int, mixed> &$db_cols[, string|null $table = null ]) : void
Parameters
- $db_cols : array<string|int, mixed>
-
the results to be returned
- $table : string|null = null
-
the table to be sampled
SetDBTable()
Sets the name of the reference table for the instance.
public
SetDBTable(string $table) : void
Parameters
- $table : string
-
The name of the main table to set.
UpdateRecord()
Make an update in the DB
public
UpdateRecord(string|null $table, string $conditions, array<string, string> $items, array<string|int, string> $conditions_values, array<string|int, string> $types) : bool
Parameters
- $table : string|null
-
name of the table
- $conditions : string
-
of the update
- $items : array<string, string>
-
associative array FIELD_NAME => FIELD_VALUE
- $conditions_values : array<string|int, string>
-
values of the conditions
- $types : array<string|int, string>
-
of DB table fields
Return values
bool —true if the update has been made