50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
|
<?php
|
||
|
// IDbConnection.php
|
||
|
// Created: 2021-04-30
|
||
|
// Updated: 2022-02-27
|
||
|
|
||
|
namespace Index\Data;
|
||
|
|
||
|
use Index\ICloseable;
|
||
|
|
||
|
/**
|
||
|
* Represents a connection to a database service.
|
||
|
*/
|
||
|
interface IDbConnection extends ICloseable {
|
||
|
/**
|
||
|
* Returns the ID of the last inserted row.
|
||
|
*
|
||
|
* @return int|string Last inserted ID.
|
||
|
*/
|
||
|
function getLastInsertId(): int|string;
|
||
|
|
||
|
/**
|
||
|
* Prepares a statement for execution and returns a database statement instance.
|
||
|
*
|
||
|
* The statement should use question mark (?) parameters.
|
||
|
*
|
||
|
* @param string $query SQL query to prepare.
|
||
|
* @return IDbStatement An instance of an implementation of IDbStatement.
|
||
|
*/
|
||
|
function prepare(string $query): IDbStatement;
|
||
|
|
||
|
/**
|
||
|
* Executes a statement and returns a database result instance.
|
||
|
*
|
||
|
* @param string $query SQL query to execute.
|
||
|
* @return IDbResult An instance of an implementation of IDbResult
|
||
|
*/
|
||
|
function query(string $query): IDbResult;
|
||
|
|
||
|
/**
|
||
|
* Executes a statement and returns how many rows are affected.
|
||
|
*
|
||
|
* Does not request results back from the database and thus should have better
|
||
|
* performance if the consumer doesn't care about them.
|
||
|
*
|
||
|
* @param string $query SQL query to execute.
|
||
|
* @return int|string Number of rows affected by the query.
|
||
|
*/
|
||
|
function execute(string $query): int|string;
|
||
|
}
|