FacturaScripts

DataBase

Generic class of access to the database, either MySQL or PostgreSQL.

Table of Contents

CHANNEL 'database'
$engine Link to the database engine selected in the configuration. DataBaseEngine
$link The link with de database. resource
$miniLog Manage the log of all controllers, models and database. MiniLog
$tables List of tables in the database. array
__construct() DataBase constructor and prepare the class to use it. mixed
beginTransaction() Start a transaction in the database. bool
close() Disconnect from the database. bool
commit() Record the statements executed in the database. bool
connect() Connect to the database. bool
connected() Returns True if it is connected to the database. bool
escapeColumn() Escape the quotes from the column name. string
escapeString() Escape the quotes from the text string. string
exec() Execute SQL statements on the database (inserts, updates or deletes). bool
getColumns() Returns an array with the columns of a given table. array
getConstraints() Returns an array with the constraints of a table. array
getEngine() Return the database engine used DataBaseEngine
getIndexes() Returns an array with the indices of a given table. array
getOperator() Gets the operator for the database engine string
getTables() Returns an array with the names of the tables in the database. array
inTransaction() Indicates if there is an open transaction. bool
lastval() Returns the last ID assigned when doing an INSERT in the database. int|bool
rollback() Undo the statements executed in the database. bool
select() Execute a SQL statement of type select, and return an array with the results, or an empty array in case of failure. array
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. array
tableExists() Returns True if the table exists, False otherwise. bool
updateSequence() mixed
var2str() Transforms a variable into a valid text string to be used in a SQL query. string
version() Returns the used database engine and the version. string

Constants

Properties

$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 $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

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( $name : string ) : string
Parameters
$name : string
Return values
string

escapeString()

Escape the quotes from the text string.

public escapeString( $str : string ) : string
Parameters
$str : string
Return values
string

exec()

Execute SQL statements on the database (inserts, updates or deletes).

public exec( $sql : string ) : 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( $tableName : string ) : array
Parameters
$tableName : string
Return values
array

getConstraints()

Returns an array with the constraints of a table.

public getConstraints( $tableName : string [, $extended : bool = false ] ) : array
Parameters
$tableName : string
$extended : bool = false
Return values
array

getIndexes()

Returns an array with the indices of a given table.

public getIndexes( $tableName : string ) : array
Parameters
$tableName : string
Return values
array

getOperator()

Gets the operator for the database engine

public getOperator( $operator : string ) : string
Parameters
$operator : string
Return values
string

getTables()

Returns an array with the names of the tables in the database.

public getTables( ) : array
Return values
array

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( $sql : string ) : array
Parameters
$sql : string
Return values
array

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( $sql : string [, $limit : int = FS_ITEM_LIMIT ] , $offset : int ) : array

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

tableExists()

Returns True if the table exists, False otherwise.

public tableExists( $tableName : string [, $list : array = [] ] ) : bool
Parameters
$tableName : string
$list : array = []
Return values
bool

updateSequence()

public updateSequence( $tableName : string , $fields : array ) : mixed
Parameters
$tableName : string
$fields : array
Return values
mixed

var2str()

Transforms a variable into a valid text string to be used in a SQL query.

public var2str( $val : mixed ) : string
Parameters
$val : mixed
Return values
string

version()

Returns the used database engine and the version.

public version( ) : string
Return values
string

Search results