3
declare(strict_types=1);
6
* This file is part of CodeIgniter 4 framework.
8
* (c) CodeIgniter Foundation <admin@codeigniter.com>
10
* For the full copyright and license information, please view
11
* the LICENSE file that was distributed with this source code.
14
namespace CodeIgniter\Database;
17
* @template TConnection
20
* @property false|object|resource $connID
21
* @property-read string $DBDriver
23
interface ConnectionInterface
26
* Initializes the database connection/settings.
30
public function initialize();
33
* Connect to the database.
35
* @return false|object|resource
36
* @phpstan-return false|TConnection
38
public function connect(bool $persistent = false);
41
* Create a persistent database connection.
43
* @return false|object|resource
44
* @phpstan-return false|TConnection
46
public function persistentConnect();
49
* Keep or establish the connection if no queries have been sent for
50
* a length of time exceeding the server's idle timeout.
54
public function reconnect();
57
* Returns the actual connection object. If both a 'read' and 'write'
58
* connection has been specified, you can pass either term in to
59
* get that connection. If you pass either alias in and only a single
60
* connection is present, it must return the sole connection.
62
* @return false|object|resource
63
* @phpstan-return false|TConnection
65
public function getConnection(?string $alias = null);
68
* Select a specific database table to use.
72
public function setDatabase(string $databaseName);
75
* Returns the name of the current database being used.
77
public function getDatabase(): string;
80
* Returns the last error encountered by this connection.
81
* Must return this format: ['code' => string|int, 'message' => string]
82
* intval(code) === 0 means "no error".
84
* @return array<string, int|string>
86
public function error(): array;
89
* The name of the platform in use (MySQLi, mssql, etc)
91
public function getPlatform(): string;
94
* Returns a string containing the version of the database being used.
96
public function getVersion(): string;
99
* Orchestrates a query against the database. Queries must use
100
* Database\Statement objects to store the query and build it.
101
* This method works with the cache.
103
* Should automatically handle different connections for read/write
106
* @param array|string|null $binds
108
* @return BaseResult|bool|Query
109
* @phpstan-return BaseResult<TConnection, TResult>|bool|Query
111
public function query(string $sql, $binds = null);
114
* Performs a basic query against the database. No binding or caching
115
* is performed, nor are transactions handled. Simply takes a raw
116
* query string and returns the database-specific result id.
118
* @return false|object|resource
119
* @phpstan-return false|TResult
121
public function simpleQuery(string $sql);
124
* Returns an instance of the query builder for this connection.
126
* @param array|string $tableName Table name.
128
* @return BaseBuilder Builder.
130
public function table($tableName);
133
* Returns the last query's statement object.
137
public function getLastQuery();
142
* Escapes data based on type.
143
* Sets boolean and null types.
145
* @param array|bool|float|int|object|string|null $str
147
* @return array|float|int|string
148
* @phpstan-return ($str is array ? array : float|int|string)
150
public function escape($str);
153
* Allows for custom calls to the database engine that are not
154
* supported through our database layer.
156
* @param array ...$params
158
* @return array|bool|float|int|object|resource|string|null
160
public function callFunction(string $functionName, ...$params);
163
* Determines if the statement is a write-type query or not.
167
public function isWriteType($sql): bool;