DataBase
    
            
            in package
            
        
    
    
    
        
            Generic class of access to the database, either MySQL or PostgreSQL.
Tags
Table of Contents
- CHANNEL = 'database'
 - $engine : DataBaseEngine
 - Link to the database engine selected in the configuration.
 - $link : resource
 - The link with de database.
 - $miniLog : MiniLog
 - Manage the log of all controllers, models and database.
 - $tables : array<string|int, mixed>
 - List of tables in the database.
 - __construct() : mixed
 - DataBase constructor and prepare the class to use it.
 - beginTransaction() : bool
 - Start a transaction in the database.
 - castInteger() : string
 - close() : bool
 - Disconnect from the database.
 - commit() : bool
 - Record the statements executed in the database.
 - connect() : bool
 - Connect to the database.
 - connected() : bool
 - Returns True if it is connected to the database.
 - escapeColumn() : string
 - Escape the quotes from the column name.
 - escapeString() : string
 - Escape the quotes from the text string.
 - exec() : bool
 - Execute SQL statements on the database (inserts, updates or deletes).
 - getColumns() : array<string|int, mixed>
 - Returns an array with the columns of a given table.
 - getConstraints() : array<string|int, mixed>
 - Returns an array with the constraints of a table.
 - getEngine() : DataBaseEngine
 - Return the database engine used
 - getIndexes() : array<string|int, mixed>
 - Returns an array with the indices of a given table.
 - getOperator() : string
 - Gets the operator for the database engine
 - getTables() : array<string|int, mixed>
 - Returns an array with the names of the tables in the database.
 - inTransaction() : bool
 - Indicates if there is an open transaction.
 - lastval() : int|bool
 - Returns the last ID assigned when doing an INSERT in the database.
 - rollback() : bool
 - Undo the statements executed in the database.
 - select() : array<string|int, mixed>
 - Execute a SQL statement of type select, and return an array with the results, or an empty array in case of failure.
 - selectLimit() : array<string|int, mixed>
 - Execute a SQL statement of type select, but with pagination, and return an array with the results or an empty array in case of failure.
 - tableExists() : bool
 - Returns True if the table exists, False otherwise.
 - updateSequence() : mixed
 - var2str() : string
 - Transforms a variable into a valid text string to be used in a SQL query.
 - version() : string
 - Returns the used database engine and the version.
 
Constants
CHANNEL
    public
        mixed
    CHANNEL
    = 'database'
        
        
    
Properties
$engine
Link to the database engine selected in the configuration.
    private
    static    DataBaseEngine
    $engine
    
    
    
    
$link
The link with de database.
    private
    static    resource
    $link
    
    
    
    
$miniLog
Manage the log of all controllers, models and database.
    private
    static    MiniLog
    $miniLog
    
    
    
    
$tables
List of tables in the database.
    private
    static    array<string|int, mixed>
    $tables
     = []
    
    
    
Methods
__construct()
DataBase constructor and prepare the class to use it.
    public
                    __construct() : mixed
    
    
    
        Return values
mixed —beginTransaction()
Start a transaction in the database.
    public
                    beginTransaction() : bool
    
    
    
        Return values
bool —castInteger()
    public
                    castInteger(string $col) : string
        
        Parameters
- $col : string
 
Return values
string —close()
Disconnect from the database.
    public
                    close() : bool
    
    
    
        Return values
bool —commit()
Record the statements executed in the database.
    public
                    commit() : bool
    
    
    
        Return values
bool —connect()
Connect to the database.
    public
                    connect() : bool
    
    
    
        Return values
bool —connected()
Returns True if it is connected to the database.
    public
                    connected() : bool
    
    
    
        Return values
bool —escapeColumn()
Escape the quotes from the column name.
    public
                    escapeColumn(string $name) : string
    
        Parameters
- $name : string
 
Return values
string —escapeString()
Escape the quotes from the text string.
    public
                    escapeString(string $str) : string
    
        Parameters
- $str : string
 
Return values
string —exec()
Execute SQL statements on the database (inserts, updates or deletes).
    public
                    exec(string $sql) : bool
        To make selects, it is better to use select () or selectLimit (). If there is no open transaction, one starts, queries are executed If the transaction has opened it in the call, it closes it confirming or discarding according to whether it has gone well or has given an error
Parameters
- $sql : string
 
Return values
bool —getColumns()
Returns an array with the columns of a given table.
    public
                    getColumns(string $tableName) : array<string|int, mixed>
    
        Parameters
- $tableName : string
 
Return values
array<string|int, mixed> —getConstraints()
Returns an array with the constraints of a table.
    public
                    getConstraints(string $tableName[, bool $extended = false ]) : array<string|int, mixed>
    
        Parameters
- $tableName : string
 - $extended : bool = false
 
Return values
array<string|int, mixed> —getEngine()
Return the database engine used
    public
                    getEngine() : DataBaseEngine
    
    
    
        Return values
DataBaseEngine —getIndexes()
Returns an array with the indices of a given table.
    public
                    getIndexes(string $tableName) : array<string|int, mixed>
    
        Parameters
- $tableName : string
 
Return values
array<string|int, mixed> —getOperator()
Gets the operator for the database engine
    public
                    getOperator(string $operator) : string
    
        Parameters
- $operator : string
 
Return values
string —getTables()
Returns an array with the names of the tables in the database.
    public
                    getTables() : array<string|int, mixed>
    
    
    
        Return values
array<string|int, mixed> —inTransaction()
Indicates if there is an open transaction.
    public
                    inTransaction() : bool
    
    
    
        Return values
bool —lastval()
Returns the last ID assigned when doing an INSERT in the database.
    public
                    lastval() : int|bool
    
    
    
        Return values
int|bool —rollback()
Undo the statements executed in the database.
    public
                    rollback() : bool
    
    
    
        Return values
bool —select()
Execute a SQL statement of type select, and return an array with the results, or an empty array in case of failure.
    public
                    select(string $sql) : array<string|int, mixed>
    
        Parameters
- $sql : string
 
Return values
array<string|int, mixed> —selectLimit()
Execute a SQL statement of type select, but with pagination, and return an array with the results or an empty array in case of failure.
    public
                    selectLimit(string $sql[, int $limit = FS_ITEM_LIMIT ], int $offset) : array<string|int, mixed>
        Limit is the number of items you want to return. Offset is the result number from which you want it to start.
Parameters
- $sql : string
 - $limit : int = FS_ITEM_LIMIT
 - $offset : int
 
Return values
array<string|int, mixed> —tableExists()
Returns True if the table exists, False otherwise.
    public
                    tableExists(string $tableName[, array<string|int, mixed> $list = [] ]) : bool
    
        Parameters
- $tableName : string
 - $list : array<string|int, mixed> = []
 
Return values
bool —updateSequence()
    public
                    updateSequence(string $tableName, array<string|int, mixed> $fields) : mixed
    
        Parameters
- $tableName : string
 - $fields : array<string|int, mixed>
 
Return values
mixed —var2str()
Transforms a variable into a valid text string to be used in a SQL query.
    public
                    var2str(mixed $val) : string
    
        Parameters
- $val : mixed
 
Return values
string —version()
Returns the used database engine and the version.
    public
                    version() : string