Ubiquity  2.4.3
php rapid development framework
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. More...
 
 connect ()
 Creates the Db instance and realize a safe connection. More...
 
 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. More...
 
 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) More...
 
 freePool ($db)
 For databases with Connection pool (put a dbInstance in pool wrapper) More...
 
 setPool ($pool)
 
 getSpecificSQL ($key, ?array $params=null)
 
 setCacheInstance (DbCache $cache)
 
 getCacheInstance ()
 
- Public Member Functions inherited from DatabaseOperationsTrait
 getDSN ()
 
 getDbObject ()
 
 _connect ()
 
 query ($sql)
 Executes an SQL statement, returning a result set as a statement object. More...
 
 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=null)
 
 getUpdateStatement ($sql)
 
 prepareAndExecuteUpdate ($sql, $parameters=null)
 Prepares a statement and execute a query for update (INSERT, UPDATE, DELETE...) More...
 
 execute ($sql)
 Execute an SQL statement and return the number of affected rows (INSERT, UPDATE or DELETE) More...
 
 prepareStatement ($sql)
 Prepares a statement for execution and returns a statement object. More...
 
 prepareNamedStatement (string $name, string $sql)
 Prepares and returns a statement for execution and gives it a name. More...
 
 getNamedStatement (string $name, ?string $sql=null)
 Returns the statement corresponding to the name. More...
 
 bindValueFromStatement ($statement, $parameter, $value)
 Sets $value to $parameter. More...
 
 lastInserId ($name=null)
 Returns the last insert id. More...
 
 count ($tableName, $condition='')
 Returns the number of records in $tableName matching with the condition passed as a parameter. More...
 
 queryColumn ($query, $columnNumber=null)
 
 fetchAll ($query, $mode=null)
 
 isConnected ()
 
 ping ()
 
- Public Member Functions inherited from DatabaseTransactionsTrait
 beginTransaction ()
 Initiates a transaction. More...
 
 commit ()
 Commits a transaction. More...
 
 commitToLevel ($transactionLevel)
 Commits nested transactions up to level $transactionLevel. More...
 
 commitAll ()
 Commits all nested transactions (up to level 0) More...
 
 rollBack ()
 Rolls back a transaction. More...
 
 rollBackToLevel ($transactionLevel)
 Rolls back nested transactions up to level $transactionLevel. More...
 
 rollBackAll ()
 Rolls back all nested transactions (up to level 0) More...
 
 inTransaction ()
 Checks if inside a transaction. More...
 
 callInTransaction ($callback,... $parameters)
 Call a callback with an array of parameters in a transaction. More...
 
- 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)
 

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. More...
 
static getAvailableWrappers ()
 

Data Fields

 $quote
 

Static Public Attributes

static $wrappers = [ 'pdo' => \Ubiquity\db\providers\pdo\PDOWrapper::class
 

Protected Attributes

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

Private Member Functions

 setDbWrapperClass ($dbWrapperClass, $dbType)
 

Private Attributes

static $dbType => '\Ubiquity\db\providers\tarantool\TarantoolWrapper','mysqli' => '\Ubiquity\db\providers\mysqli\MysqliWrapper','swoole' => '\Ubiquity\db\providers\swoole\SwooleWrapper' ]
 
 $serverName
 
 $port
 
 $dbName
 
 $user
 
 $password
 
 $cache
 
 $options
 

Additional Inherited Members

- Protected Member Functions inherited from DatabaseTransactionsTrait
 nestable ()
 

Detailed Description

Ubiquity Generic database class.

Ubiquity$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 56 of file Database.php.

Member Function Documentation

◆ close()

close ( )

Closes the active connection.

Definition at line 223 of file Database.php.

◆ connect()

connect ( )

Creates the Db instance and realize a safe connection.

Exceptions
DBException
Returns
boolean

Definition at line 90 of file Database.php.

◆ freePool()

freePool (   $db)

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

Definition at line 283 of file Database.php.

◆ getAvailableDrivers()

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

Definition at line 149 of file Database.php.

◆ getAvailableWrappers()

static getAvailableWrappers ( )
static

Definition at line 291 of file Database.php.

◆ getCacheInstance()

getCacheInstance ( )

Definition at line 314 of file Database.php.

◆ getCondition()

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

Definition at line 265 of file Database.php.

◆ getDbName()

getDbName ( )
Returns
string

Definition at line 136 of file Database.php.

◆ getDbType()

getDbType ( )
Returns
mixed

Definition at line 158 of file Database.php.

◆ getDSN()

getDSN ( )

Definition at line 100 of file Database.php.

◆ getInsertValues()

getInsertValues (   $keyAndValues)

Definition at line 257 of file Database.php.

◆ getOptions()

getOptions ( )
Returns
array

Definition at line 176 of file Database.php.

◆ getPassword()

getPassword ( )
Returns
string

Definition at line 167 of file Database.php.

◆ getPort()

getPort ( )
Returns
string

Definition at line 127 of file Database.php.

◆ getServerName()

getServerName ( )
Returns
string

Definition at line 109 of file Database.php.

◆ getSpecificSQL()

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

Definition at line 301 of file Database.php.

◆ getUpdateFieldsKeyAndValues()

getUpdateFieldsKeyAndValues (   $keyAndValues,
  $fields 
)

Definition at line 249 of file Database.php.

◆ getUser()

getUser ( )
Returns
string

Definition at line 145 of file Database.php.

◆ pool()

pool ( )

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

Definition at line 276 of file Database.php.

◆ quoteValue()

quoteValue (   $value,
  $type = 2 
)

Definition at line 245 of file Database.php.

◆ setCacheInstance()

setCacheInstance ( DbCache  $cache)

Definition at line 310 of file Database.php.

◆ setDbName()

setDbName (   $dbName)
Parameters
string$dbName

Definition at line 192 of file Database.php.

◆ setDbType()

setDbType (   $dbType)

Definition at line 117 of file Database.php.

◆ setDbWrapperClass()

setDbWrapperClass (   $dbWrapperClass,
  $dbType 
)
private

Definition at line 80 of file Database.php.

◆ setOptions()

setOptions (   $options)
Parameters
array$options

Definition at line 216 of file Database.php.

◆ setPassword()

setPassword (   $password)
Parameters
string$password

Definition at line 208 of file Database.php.

◆ setPool()

setPool (   $pool)

Definition at line 287 of file Database.php.

◆ setPort()

setPort (   $port)
Parameters
string$port

Definition at line 184 of file Database.php.

◆ setServerName()

setServerName (   $serverName)

Definition at line 113 of file Database.php.

◆ setUser()

setUser (   $user)
Parameters
string$user

Definition at line 200 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
|NULL

Definition at line 234 of file Database.php.

Field Documentation

◆ $cache

$cache
private

Definition at line 33 of file Database.php.

◆ $dbName

$dbName
private

Definition at line 30 of file Database.php.

◆ $dbType

$dbType => '\Ubiquity\db\providers\tarantool\TarantoolWrapper','mysqli' => '\Ubiquity\db\providers\mysqli\MysqliWrapper','swoole' => '\Ubiquity\db\providers\swoole\SwooleWrapper' ]
private

Definition at line 26 of file Database.php.

◆ $options

$options
private

Definition at line 34 of file Database.php.

◆ $password

$password
private

Definition at line 32 of file Database.php.

◆ $port

$port
private

Definition at line 29 of file Database.php.

◆ $quote

$quote

Definition at line 35 of file Database.php.

◆ $serverName

$serverName
private

Definition at line 28 of file Database.php.

◆ $user

$user
private

Definition at line 31 of file Database.php.

◆ $wrapperObject

$wrapperObject
protected

Definition at line 41 of file Database.php.

◆ $wrappers

$wrappers = [ 'pdo' => \Ubiquity\db\providers\pdo\PDOWrapper::class
static

Definition at line 26 of file Database.php.


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