ringfinger/backend/classes/core/DatabaseInterface.php

80 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2020-08-17 23:46:58 +02:00
<?php
interface DatabaseInterface
{
2020-08-23 12:37:39 +02:00
public const ORDER_ASC = true;
public const ORDER_DESC = false;
2020-08-17 23:46:58 +02:00
2020-08-23 12:37:39 +02:00
/**
* Has to close the connection.
*/
public function __destruct();
2020-08-17 23:46:58 +02:00
2020-08-23 12:37:39 +02:00
/**
* Sends an sql query to the database.
*/
public function Query(string $query, array $params = []): void;
2020-08-17 23:46:58 +02:00
2020-08-23 12:37:39 +02:00
/**
* @return array
*/
public function getResult(): array;
2020-08-17 23:46:58 +02:00
2020-08-23 12:37:39 +02:00
/**
* Selects backend from a table.
*/
public function Select(
string $tableName,
array $fields = [],
array $conditions = [],
int $limit = 0,
array $orderBy = [],
bool $asc = true,
int $offset = 0
): array;
2020-08-17 23:46:58 +02:00
2020-08-23 12:37:39 +02:00
/**
* Deletes rows from a table.
*/
public function Delete(string $table, array $conditions): void;
2020-08-17 23:46:58 +02:00
2020-08-23 12:37:39 +02:00
/**
* Inserts a new row into the table.
*/
public function Insert(string $table, array $fields): ?int;
2020-08-17 23:46:58 +02:00
2020-08-23 12:37:39 +02:00
/**
* Edits backend inside a table.
*/
public function Update(string $table, array $fields, array $conditions): void;
2020-08-17 23:46:58 +02:00
2020-08-23 12:37:39 +02:00
/**
* Returns the number of entries found.
*/
public function Count(string $table, array $conditions = []): int;
2020-08-17 23:46:58 +02:00
2020-08-23 12:37:39 +02:00
/*
* Returns if there's an open transaction.
*/
public function hasTransaction(): bool;
2020-08-18 11:46:03 +02:00
2020-08-23 12:37:39 +02:00
/*
* Starts a transaction that can later be committed or rolled back.
*/
public function startTransaction(): void;
2020-08-18 11:46:03 +02:00
2020-08-23 12:37:39 +02:00
/*
* Quits a current transaction without saving.
*/
public function rollback(): void;
2020-08-18 11:46:03 +02:00
2020-08-23 12:37:39 +02:00
/*
* Saves and exits a current transaction.
*/
public function commit(): void;
2020-08-18 11:46:03 +02:00
2020-08-23 12:37:39 +02:00
/**
* Returns the primary key from the last inserted row.
*/
public function GetLastInsertedId(): int;
2020-08-17 23:46:58 +02:00
}