Jet\Db_Backend_Interface

The interface defining the backend of the direct database connection system.

Method Overview

Method Meaning of
public __construct(
Db_Backend_Config $config
)
The constructor performs the initialization and connection to the database server based on the passed instance of the connection configuration.
public __destruct(
)
The destructor should ideally perform a disconnect from the database server, or other necessary termination operations.
public disconnect(
): void
Performs a disconnect from the database server.
public getConfig(
): Db_Backend_Config
Returns the configuration of the connection to the database server.
public execute(
string $query,
array $query_data = []
): int
Executes SQL query of type INSERT, UPDATE, DELETE (and similar) and returns the number of affected rows.
Parameters:
  • $query
    The query itself. It can be already in the final form or contain parameters - see below.
  • $query_data
    Quite simply, we can just say that the parameters behave like in \PDOStatement::execute. Thus, the query contains the positions for their insertion, $query_data contains the associated array, where the key corresponds to the name of the position in the query. Let's illustrate this right away: $db Db::get();
    $db->execute('INSERT INTO some_table SET
        name=:name,
        weight=:weight'

        [
            
    'name' => 'Some Name',
            
    'weight' => 123456
        
    ]);
Of course, the method must cooperate with the profiler and inform it about the query.
public query(
string $query,
array $query_params = [],
?callable $result_handler=null
): iterable
Executes a SELECT query and returns the result, which is processed (optionally) by the given handler before returning.
Parameters:
  • $query, query_params
    See method execute.
  • $result_handler
    If this optional parameter is defined, then the result of the SQL query is passed to the handler for processing (the return value of the handler is then the return value of the execute method).
Of course, the method must cooperate with the profiler and inform it about the query.
public fetchAll(
string $query,
array $query_data=[]
): array
Executes a SELECT query with the result converted to a regular array.
Parameters:
  • $query, query_params
    See method execute.
Of course, the method must cooperate with the profiler and inform it about the query.
public fetchRow(
string $query,
array $query_data = []
): array|bool
Performs a SELECT query and returns the first row of the result. It is therefore used where a single line result is expected.
Parameters:
  • $query, query_params
    See method execute
Of course, the method must cooperate with the profiler and inform it about the query.
public fetchAssoc(
string $query,
array $query_data=[],
?string $key_column = null
): array
Executes a SELECT query with the result converted to a regular array, where the key of this array is the value of the column specified by the $key_column parameter, or the first column of the result if the $key_column parameter is not defined.
Parameters:
  • $query, query_params
    See method execute.
  • $key_column
    Určuje název sloupce jehož hodnota bude použita jako klíč pole výsledku.
Of course, the method must cooperate with the profiler and inform it about the query.
public fetchCol(
string $query,
array $query_data=[],
?string $column=null
): array
Executes a SELECT query, but does not return the entire result, but an array containing the values of the column specified by the $column parameter, or the first column of the result if this parameter is not defined.
Parameters:
  • $query, query_params
    See method execute.
  • $column
    Specifies the name of the column whose values will be returned in the array.
Of course, the method must cooperate with the profiler and inform it about the query.
public fetchPairs(
string $query,
array $query_data=[],
?string $key_column = null,
?string $value_column = null
): array
Provede dotaz typu SELECT a vrátí asociované pole, kde klíčem je sloupec určený parametrem $key_column a hodnotou pole určené parametrem $value_column. Pokud parametry $key_column a $value_column nejsou definovány, pak jsou použity hodnoty prvního a druhého sloupce výsledku.
Parametry:
  • $query, query_params
    See method execute.
  • $key_column
    Specifies the name of the column whose values will be used as keys for the resulting array.
  • $value_column
    Specifies the name of the column whose values will be used as the values of the result field.
Of course, the method must cooperate with the profiler and inform it about the query.
public fetchOne(
string $query,
array $query_data = [],
?string $column = null
): mixed
Performs a SELECT query and returns the value of the column specified by the $column parameter (or the first column if the parameter is not defined) of the first row of the result. It is therefore used where you want a single value from the result.
Parameters:
  • $query, query_params
    See method execute.
  • $column
    Specifies the name of the column whose value will be taken as the result.
Of course, the method must cooperate with the profiler and inform it about the query.
public beginTransaction(
) : bool
Start transaction.
public commit(
) : bool
Commit transaction.
public rollBack(
) : bool
Roll back transaction.
public inTransaction(
) : bool
Indicates whether the transaction is in progress.
public lastInsertId(
string $name = null
) : string
Returns the last inserted ID (e.g. autoincrement).
Previous chapter
Jet\Db
Next chapter
Jet\Db_Backend_PDO