Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
Database Class Reference

Ubiquity Generic database class. More...

+ Inheritance diagram for Database:

Public Member Functions

 __construct ($dbWrapperClass, $dbType, $dbName, $serverName="127.0.0.1", $port="3306", $user="root", $password="", $options=[], $cache=false, $pool=null)
 Constructor.
 
 connect ()
 Creates the Db instance and realize a safe connection.
 
 getDSN ()
 
 getServerName ()
 
 setServerName ($serverName)
 
 setDbType ($dbType)
 
 getPort ()
 
 getDbName ()
 
 getUser ()
 
 getDbType ()
 
 getPassword ()
 
 getOptions ()
 
 setPort ($port)
 
 setDbName ($dbName)
 
 setUser ($user)
 
 setPassword ($password)
 
 setOptions ($options)
 
 close ()
 Closes the active connection.
 
 quoteValue ($value, $type=2)
 
 getUpdateFieldsKeyAndValues ($keyAndValues, $fields)
 
 getInsertValues ($keyAndValues)
 
 getCondition (array $keyValues, $separator=' AND ')
 
 pool ()
 For databases with Connection pool (retrieve a new dbInstance from pool wrapper)
 
 freePool ($db)
 For databases with Connection pool (put a dbInstance in pool wrapper)
 
 setPool ($pool)
 
 getSpecificSQL ($key, ?array $params=null)
 
 setCacheInstance (DbCache $cache)
 
 getCacheInstance ()
 
- Public Member Functions inherited from DatabaseOperationsTrait
 getDbObject ()
 
 _connect ()
 
 query ($sql)
 Executes an SQL statement, returning a result set as a statement object.
 
 prepareAndExecute ($tableName, $condition, $fields, $parameters=null, $useCache=false, $one=false)
 
 _optExecuteAndFetch ($statement, $tableName, $condition, $parameters=null, $useCache=false, $one=false)
 
 _optExecuteAndFetchNoCache ($statement, $parameters=null, $one=false)
 
 getDaoPreparedStatement ($tableName, $condition, $fields)
 
 prepareAndExecuteNoCache ($tableName, $condition, $fields, $parameters=null)
 
 storeCache ()
 
 prepareAndFetchAll ($sql, $parameters=null, $mode=null)
 
 prepareAndFetchOne ($sql, $parameters=null, $mode=null)
 
 prepareAndFetchAllColumn ($sql, $parameters=null, $column=null)
 
 prepareAndFetchColumn ($sql, $parameters=null, $columnNumber=0)
 
 getUpdateStatement ($sql)
 
 prepareAndExecuteUpdate ($sql, $parameters=null)
 Prepares a statement and execute a query for update (INSERT, UPDATE, DELETE...)
 
 execute ($sql)
 Execute an SQL statement and return the number of affected rows (INSERT, UPDATE or DELETE)
 
 prepareStatement ($sql)
 Prepares a statement for execution and returns a statement object.
 
 prepareNamedStatement (string $name, string $sql)
 Prepares and returns a statement for execution and gives it a name.
 
 getNamedStatement (string $name, ?string $sql=null)
 Returns the statement corresponding to the name.
 
 bindValueFromStatement ($statement, $parameter, $value)
 Sets $value to $parameter.
 
 lastInserId ($name=null)
 Returns the last insert id.
 
 count ($tableName, $condition='')
 Returns the number of records in $tableName matching with the condition passed as a parameter.
 
 queryColumn ($query, $columnNumber=null)
 
 fetchAll ($query, $mode=null)
 
 isConnected ()
 
 ping ()
 
- Public Member Functions inherited from DatabaseTransactionsTrait
 beginTransaction ()
 Initiates a transaction.
 
 commit ()
 Commits a transaction.
 
 commitToLevel ($transactionLevel)
 Commits nested transactions up to level $transactionLevel.
 
 commitAll ()
 Commits all nested transactions (up to level 0)
 
 rollBack ()
 Rolls back a transaction.
 
 rollBackToLevel ($transactionLevel)
 Rolls back nested transactions up to level $transactionLevel.
 
 rollBackAll ()
 Rolls back all nested transactions (up to level 0)
 
 inTransaction ()
 Checks if inside a transaction.
 
 callInTransaction ($callback,... $parameters)
 Call a callback with an array of parameters in a transaction.
 
 setIsolationLevel ($isolationLevel)
 Sets the isolation level for transactions.
 
- Public Member Functions inherited from DatabaseMetadatas
 getTablesName ()
 
 getPrimaryKeys ($tableName)
 
 getFieldsInfos ($tableName)
 
 getForeignKeys ($tableName, $pkName, $dbName=null)
 
 getRowNum (string $tableName, string $pkName, string $condition)
 
 getPHPType (string $dbType)
 
 migrateOperation (string $operation)
 Returns the SQL command for a migration operation.
 

Static Public Member Functions

static getAvailableDrivers ($dbWrapperClass=\Ubiquity\db\providers\pdo\PDOWrapper::class)
 
static start (string $offset=null, ?array $config=null)
 Starts and returns a database instance corresponding to an offset in config.
 
static getAvailableWrappers ()
 

Data Fields

 $quote
 

Static Public Attributes

static $wrappers = [ 'pdo' => \Ubiquity\db\providers\pdo\PDOWrapper::class,'tarantool' => '\Ubiquity\db\providers\tarantool\TarantoolWrapper','mysqli' => '\Ubiquity\db\providers\mysqli\MysqliWrapper','swoole' => '\Ubiquity\db\providers\swoole\SwooleWrapper' ]
 

Protected Attributes

 $wrapperObject
 
- Protected Attributes inherited from DatabaseTransactionsTrait
 $transactionLevel = 0
 

Private Member Functions

 setDbWrapperClass ($dbWrapperClass, $dbType)
 

Private Attributes

 $dbType
 
 $serverName
 
 $port
 
 $dbName
 
 $user
 
 $password
 
 $cache
 
 $options
 

Additional Inherited Members

- Protected Member Functions inherited from DatabaseTransactionsTrait
 nestable ()
 

Detailed Description

Ubiquity Generic database class.

Ubiquity\db$Database This class is part of Ubiquity

Author
jcheron myadd.nosp@m.ress.nosp@m.mail@.nosp@m.gmai.nosp@m.l.com
Version
1.1.4

Definition at line 25 of file Database.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $dbWrapperClass,
  $dbType,
  $dbName,
  $serverName = "127.0.0.1",
  $port = "3306",
  $user = "root",
  $password = "",
  $options = [ ],
  $cache = false,
  $pool = null 
)

Constructor.

Parameters
string$dbWrapperClass
string$dbName
string$serverName
string$port
string$user
string$password
array$options
boolean | string$cache
mixed$pool

Definition at line 57 of file Database.php.

Member Function Documentation

◆ close()

close ( )

Closes the active connection.

Definition at line 224 of file Database.php.

◆ connect()

connect ( )

Creates the Db instance and realize a safe connection.

Exceptions
DBException
Returns
boolean

Definition at line 91 of file Database.php.

◆ freePool()

freePool (   $db)

For databases with Connection pool (put a dbInstance in pool wrapper)

Definition at line 284 of file Database.php.

◆ getAvailableDrivers()

static getAvailableDrivers (   $dbWrapperClass = \Ubiquity\db\providers\pdo\PDOWrapper::class)
static

Definition at line 150 of file Database.php.

◆ getAvailableWrappers()

static getAvailableWrappers ( )
static

Definition at line 292 of file Database.php.

◆ getCacheInstance()

getCacheInstance ( )

Definition at line 315 of file Database.php.

◆ getCondition()

getCondition ( array  $keyValues,
  $separator = ' AND ' 
)

Definition at line 266 of file Database.php.

◆ getDbName()

getDbName ( )
Returns
string @codeCoverageIgnore

Definition at line 137 of file Database.php.

◆ getDbType()

getDbType ( )
Returns
mixed @codeCoverageIgnore

Definition at line 159 of file Database.php.

◆ getDSN()

getDSN ( )

Reimplemented from DatabaseOperationsTrait.

Definition at line 101 of file Database.php.

◆ getInsertValues()

getInsertValues (   $keyAndValues)

Definition at line 258 of file Database.php.

◆ getOptions()

getOptions ( )
Returns
array @codeCoverageIgnore

Definition at line 177 of file Database.php.

◆ getPassword()

getPassword ( )
Returns
string @codeCoverageIgnore

Definition at line 168 of file Database.php.

◆ getPort()

getPort ( )
Returns
string @codeCoverageIgnore

Definition at line 128 of file Database.php.

◆ getServerName()

getServerName ( )
Returns
string @codeCoverageIgnore

Definition at line 110 of file Database.php.

◆ getSpecificSQL()

getSpecificSQL (   $key,
?array  $params = null 
)

Definition at line 302 of file Database.php.

◆ getUpdateFieldsKeyAndValues()

getUpdateFieldsKeyAndValues (   $keyAndValues,
  $fields 
)

Definition at line 250 of file Database.php.

◆ getUser()

getUser ( )
Returns
string @codeCoverageIgnore

Definition at line 146 of file Database.php.

◆ pool()

pool ( )

For databases with Connection pool (retrieve a new dbInstance from pool wrapper)

Definition at line 277 of file Database.php.

◆ quoteValue()

quoteValue (   $value,
  $type = 2 
)

Definition at line 246 of file Database.php.

◆ setCacheInstance()

setCacheInstance ( DbCache  $cache)

Definition at line 311 of file Database.php.

◆ setDbName()

setDbName (   $dbName)
Parameters
string$dbName

Definition at line 193 of file Database.php.

◆ setDbType()

setDbType (   $dbType)

Definition at line 118 of file Database.php.

◆ setDbWrapperClass()

setDbWrapperClass (   $dbWrapperClass,
  $dbType 
)
private

Definition at line 81 of file Database.php.

◆ setOptions()

setOptions (   $options)
Parameters
array$options

Definition at line 217 of file Database.php.

◆ setPassword()

setPassword (   $password)
Parameters
string$password

Definition at line 209 of file Database.php.

◆ setPool()

setPool (   $pool)

Definition at line 288 of file Database.php.

◆ setPort()

setPort (   $port)
Parameters
string$port

Definition at line 185 of file Database.php.

◆ setServerName()

setServerName (   $serverName)

Definition at line 114 of file Database.php.

◆ setUser()

setUser (   $user)
Parameters
string$user

Definition at line 201 of file Database.php.

◆ start()

static start ( string  $offset = null,
?array  $config = null 
)
static

Starts and returns a database instance corresponding to an offset in config.

Parameters
string$offset
array$configUbiquity config file content
Returns
\Ubiquity\db\Database|NULL

Definition at line 235 of file Database.php.

Field Documentation

◆ $cache

$cache
private

Definition at line 34 of file Database.php.

◆ $dbName

$dbName
private

Definition at line 31 of file Database.php.

◆ $dbType

$dbType
private

Definition at line 28 of file Database.php.

◆ $options

$options
private

Definition at line 35 of file Database.php.

◆ $password

$password
private

Definition at line 33 of file Database.php.

◆ $port

$port
private

Definition at line 30 of file Database.php.

◆ $quote

$quote

Definition at line 36 of file Database.php.

◆ $serverName

$serverName
private

Definition at line 29 of file Database.php.

◆ $user

$user
private

Definition at line 32 of file Database.php.

◆ $wrapperObject

$wrapperObject
protected

Definition at line 42 of file Database.php.

◆ $wrappers

$wrappers = [ 'pdo' => \Ubiquity\db\providers\pdo\PDOWrapper::class,'tarantool' => '\Ubiquity\db\providers\tarantool\TarantoolWrapper','mysqli' => '\Ubiquity\db\providers\mysqli\MysqliWrapper','swoole' => '\Ubiquity\db\providers\swoole\SwooleWrapper' ]
static

Definition at line 27 of file Database.php.


The documentation for this class was generated from the following file: