Documentation

Db extends Connection
in package

Database connection class.

Tags
copyright

YetiForce S.A.

license

YetiForce Public License 6.5 (licenses/LicenseEN.txt or yetiforce.com)

author

Mariusz Krzaczkowski m.krzaczkowski@yetiforce.com

author

Radosław Skrzypczak r.skrzypczak@yetiforce.com

Table of Contents

ASC  = 'ASC'
Sorting order flag.
DESC  = 'DESC'
Sorting order flag.
$commandClass  : string
$connectCache  : bool
$dbName  : string
$dbType  : string
$emulatePrepare  : bool
$host  : string
$port  : int
$schemaCache  : Cache|string
$schemaMap  : mixed
{@inheritdoc}
$cache  : Db
$config  : array<string|int, mixed>
createTable()  : bool
Creating a new DB table.
getConfig()  : array<string|int, mixed>
Load database connection configuration.
getDbInfo()  : array<string|int, mixed>
Get database info.
getInfo()  : array<string|int, mixed>
Get info database server.
getInstance()  : Db
Creates the Db connection instance.
getLastInsertID()  : string
Returns the ID of the last inserted row or sequence value.
getPrimaryKey()  : type
Get table primary keys.
getTableKeys()  : array<string|int, mixed>
Get table keys.
getUniqueID()  : int
Get table unique ID. Temporary function.
isTableExists()  : bool
Check if table is present in database.
quoteSql()  : string
Processes a SQL statement by quoting table and column names that are enclosed within double brackets.
setConfig()  : mixed
Set database connection configuration.
createPdoInstance()  : PDO
Creates the PDO instance.

Constants

ASC

Sorting order flag.

public mixed ASC = 'ASC'

DESC

Sorting order flag.

public mixed DESC = 'DESC'

Properties

$commandClass

public string $commandClass = '\\App\\Db\\Command'

the class used to create new database [[Command]] objects. If you want to extend the [[Command]] class, you may configure this property to use your extended version of the class

$connectCache

public static bool $connectCache = false

Enable caching database instance

$dbName

public string $dbName

Database Name

$dbType

public string $dbType

Database section

$emulatePrepare

public bool $emulatePrepare = false

whether to turn on prepare emulation. Defaults to false, meaning PDO will use the native prepare support if available. For some databases (such as MySQL), this may need to be set true so that PDO can emulate the prepare support to bypass the buggy native prepare support. The default value is null, which means the PDO ATTR_EMULATE_PREPARES value will not be changed

$host

public string $host

Host database server

$port

public int $port

Port database server

$schemaCache

public Cache|string $schemaCache = false

the cache object or the ID of the cache application component that is used to cache the table metadata

Tags
see
enableSchemaCache

$schemaMap

{@inheritdoc}

public mixed $schemaMap = [ 'pgsql' => 'App\\Db\\Drivers\\Pgsql\\Schema', // PostgreSQL 'mysqli' => 'yii\\db\\mysql\\Schema', // MySQL 'mysql' => 'App\\Db\\Drivers\\Mysql\\Schema', // MySQL 'sqlite' => 'yii\\db\\sqlite\\Schema', // sqlite 3 'sqlite2' => 'yii\\db\\sqlite\\Schema', // sqlite 2 'sqlsrv' => 'yii\\db\\mssql\\Schema', // newer MSSQL driver on MS Windows hosts 'oci' => 'yii\\db\\oci\\Schema', // Oracle driver 'mssql' => 'yii\\db\\mssql\\Schema', // older MSSQL driver on MS Windows hosts 'dblib' => 'yii\\db\\mssql\\Schema', // dblib drivers on GNU/Linux (and maybe other OSes) hosts 'cubrid' => 'yii\\db\\cubrid\\Schema', ]

$cache

private static Db $cache = []

Table of connections with database

$config

private static array<string|int, mixed> $config = []

Configuration with database

Methods

createTable()

Creating a new DB table.

public createTable(string $tableName, mixed $columns) : bool
Parameters
$tableName : string
$columns : mixed
Return values
bool

getConfig()

Load database connection configuration.

public static getConfig(string $type) : array<string|int, mixed>
Parameters
$type : string
Return values
array<string|int, mixed>

with database configuration

getDbInfo()

Get database info.

public getDbInfo() : array<string|int, mixed>
Return values
array<string|int, mixed>

getInfo()

Get info database server.

public getInfo() : array<string|int, mixed>
Return values
array<string|int, mixed>

getInstance()

Creates the Db connection instance.

public static getInstance([string $type = 'base' ]) : Db
Parameters
$type : string = 'base'

Name of database connection

Return values
Db

getLastInsertID()

Returns the ID of the last inserted row or sequence value.

public getLastInsertID([string $sequenceName = '' ]) : string
Parameters
$sequenceName : string = ''

name of the sequence object (required by some DBMS) ex. table vtiger_picklist >>> vtiger_picklist_picklistid_seq

Tags
see
https://www.php.net/manual/en/function.PDO-lastInsertId.php
Return values
string

the row ID of the last row inserted, or the last value retrieved from the sequence object

getPrimaryKey()

Get table primary keys.

public getPrimaryKey(type $tableName) : type
Parameters
$tableName : type
Return values
type

getTableKeys()

Get table keys.

public getTableKeys(string $tableName) : array<string|int, mixed>
Parameters
$tableName : string
Return values
array<string|int, mixed>

getUniqueID()

Get table unique ID. Temporary function.

public getUniqueID(string $tableName[, false|string $columnName = false ][, bool $seq = true ]) : int
Parameters
$tableName : string
$columnName : false|string = false
$seq : bool = true
Return values
int

isTableExists()

Check if table is present in database.

public isTableExists(string $tableName) : bool
Parameters
$tableName : string
Return values
bool

quoteSql()

Processes a SQL statement by quoting table and column names that are enclosed within double brackets.

public quoteSql(string $sql) : string

Tokens enclosed within double curly brackets are treated as table names, while tokens enclosed within double square brackets are column names. They will be quoted accordingly. Also, the percentage character "%" at the beginning or ending of a table name will be replaced with [[tablePrefix]].

Parameters
$sql : string

the SQL to be quoted

Return values
string

the quoted SQL

setConfig()

Set database connection configuration.

public static setConfig(array<string|int, mixed> $config[, string $type = 'base' ]) : mixed
Parameters
$config : array<string|int, mixed>
$type : string = 'base'
Return values
mixed

createPdoInstance()

Creates the PDO instance.

protected createPdoInstance() : PDO

This method is called by [[open]] to establish a DB connection. The default implementation will create a PHP PDO instance. You may override this method if the default PDO needs to be adapted for certain DBMS.

Return values
PDO

the pdo instance


        

Search results