CodeIgniter v4.5 API

ConnectionInterface

Tags
template

TConnection

template

TResult

Table of Contents

Methods

callFunction()  : array<string|int, mixed>|bool|float|int|object|resource|string|null
Allows for custom calls to the database engine that are not supported through our database layer.
connect()  : false|object|resource
Connect to the database.
error()  : array<string, int|string>
Returns the last error encountered by this connection.
escape()  : array<string|int, mixed>|float|int|string
"Smart" Escaping
getConnection()  : false|object|resource
Returns the actual connection object. If both a 'read' and 'write' connection has been specified, you can pass either term in to get that connection. If you pass either alias in and only a single connection is present, it must return the sole connection.
getDatabase()  : string
Returns the name of the current database being used.
getLastQuery()  : Query
Returns the last query's statement object.
getPlatform()  : string
The name of the platform in use (MySQLi, mssql, etc)
getVersion()  : string
Returns a string containing the version of the database being used.
initialize()  : void
Initializes the database connection/settings.
isWriteType()  : bool
Determines if the statement is a write-type query or not.
persistentConnect()  : false|object|resource
Create a persistent database connection.
query()  : BaseResult|bool|Query
Orchestrates a query against the database. Queries must use Database\Statement objects to store the query and build it.
reconnect()  : void
Keep or establish the connection if no queries have been sent for a length of time exceeding the server's idle timeout.
setDatabase()  : bool
Select a specific database table to use.
simpleQuery()  : false|object|resource
Performs a basic query against the database. No binding or caching is performed, nor are transactions handled. Simply takes a raw query string and returns the database-specific result id.
table()  : BaseBuilder
Returns an instance of the query builder for this connection.

Methods

callFunction()

Allows for custom calls to the database engine that are not supported through our database layer.

public callFunction(string $functionName, array<string|int, mixed> ...$params) : array<string|int, mixed>|bool|float|int|object|resource|string|null
Parameters
$functionName : string
$params : array<string|int, mixed>
Return values
array<string|int, mixed>|bool|float|int|object|resource|string|null

connect()

Connect to the database.

public connect([bool $persistent = false ]) : false|object|resource
Parameters
$persistent : bool = false
Tags
phpstan-return

false|TConnection

Return values
false|object|resource

error()

Returns the last error encountered by this connection.

public error() : array<string, int|string>

Must return this format: ['code' => string|int, 'message' => string] intval(code) === 0 means "no error".

Return values
array<string, int|string>

escape()

"Smart" Escaping

public escape(array<string|int, mixed>|bool|float|int|object|string|null $str) : array<string|int, mixed>|float|int|string

Escapes data based on type. Sets boolean and null types.

Parameters
$str : array<string|int, mixed>|bool|float|int|object|string|null
Tags
phpstan-return

($str is array ? array : float|int|string)

Return values
array<string|int, mixed>|float|int|string

getConnection()

Returns the actual connection object. If both a 'read' and 'write' connection has been specified, you can pass either term in to get that connection. If you pass either alias in and only a single connection is present, it must return the sole connection.

public getConnection([string|null $alias = null ]) : false|object|resource
Parameters
$alias : string|null = null
Tags
phpstan-return

false|TConnection

Return values
false|object|resource

getDatabase()

Returns the name of the current database being used.

public getDatabase() : string
Return values
string

getPlatform()

The name of the platform in use (MySQLi, mssql, etc)

public getPlatform() : string
Return values
string

getVersion()

Returns a string containing the version of the database being used.

public getVersion() : string
Return values
string

initialize()

Initializes the database connection/settings.

public initialize() : void

isWriteType()

Determines if the statement is a write-type query or not.

public isWriteType(string $sql) : bool
Parameters
$sql : string
Return values
bool

persistentConnect()

Create a persistent database connection.

public persistentConnect() : false|object|resource
Tags
phpstan-return

false|TConnection

Return values
false|object|resource

query()

Orchestrates a query against the database. Queries must use Database\Statement objects to store the query and build it.

public query(string $sql[, array<string|int, mixed>|string|null $binds = null ]) : BaseResult|bool|Query

This method works with the cache.

Should automatically handle different connections for read/write queries if needed.

Parameters
$sql : string
$binds : array<string|int, mixed>|string|null = null
Tags
phpstan-return

BaseResult<TConnection, TResult>|bool|Query

Return values
BaseResult|bool|Query

reconnect()

Keep or establish the connection if no queries have been sent for a length of time exceeding the server's idle timeout.

public reconnect() : void

setDatabase()

Select a specific database table to use.

public setDatabase(string $databaseName) : bool
Parameters
$databaseName : string
Return values
bool

simpleQuery()

Performs a basic query against the database. No binding or caching is performed, nor are transactions handled. Simply takes a raw query string and returns the database-specific result id.

public simpleQuery(string $sql) : false|object|resource
Parameters
$sql : string
Tags
phpstan-return

false|TResult

Return values
false|object|resource

table()

Returns an instance of the query builder for this connection.

public table(array<string|int, mixed>|string $tableName) : BaseBuilder
Parameters
$tableName : array<string|int, mixed>|string

Table name.

Return values
BaseBuilder

Builder.


        
On this page

Search results