25 return $this->wrapperObject->getDbInstance ();
29 $this->wrapperObject->connect ( $this->dbType, $this->dbName, $this->serverName, $this->port, $this->user, $this->password, $this->options );
39 return $this->wrapperObject->query ( $sql );
51 public function prepareAndExecute($tableName, $condition, $fields, $parameters =
null, $useCache =
false, $one =
false) {
53 if ($cache = ($useCache!==
false && (DbCache::$active || $useCache))) {
54 $result = $this->
getCacheValue ( $tableName, $condition, $parameters, $cKey );
56 if ($result ===
false) {
58 $sql=
"SELECT {$fields} FROM {$quote}{$tableName}{$quote} {$condition}";
59 Logger::info (
'Database', $sql,
'prepareAndExecute', $parameters );
60 $result = $this->wrapperObject->_optPrepareAndExecute ( $sql, $parameters, $one );
62 $this->cache->store ( $tableName, $cKey, $result );
68 private function getCacheValue($tableName, $condition, $parameters, &$cKey) {
70 if (\is_array ( $parameters )) {
71 $cKey .= \implode (
',', $parameters );
74 $result = $this->cache->fetch ( $tableName, $cKey );
75 Logger::info (
'Cache',
"fetching cache for table {$tableName} with condition : {$condition}",
'Database::prepareAndExecute', $parameters );
76 }
catch ( \Exception $e ) {
77 throw new CacheException (
"Cache is not created in Database constructor" );
82 public function _optExecuteAndFetch($statement, $tableName, $condition, $parameters =
null, $useCache =
false, $one =
false) {
84 if ($cache = ($useCache!==
false && (DbCache::$active || $useCache))) {
85 $result = $this->
getCacheValue ( $tableName, $condition, $parameters, $cKey );
87 if ($result ===
false) {
88 $result = $this->wrapperObject->_optExecuteAndFetch ( $statement, $parameters, $one );
90 $this->cache->store ( $tableName, $cKey, $result );
97 return $this->wrapperObject->_optExecuteAndFetch ( $statement, $parameters, $one );
102 return $this->wrapperObject->prepareStatement (
"SELECT {$fields} FROM {$quote}{$tableName}{$quote} {$condition}" );
107 return $this->wrapperObject->_optPrepareAndExecute (
"SELECT {$fields} FROM {$quote}{$tableName}{$quote} {$condition}", $parameters );
111 $this->cache->storeDeferred ();
115 return $this->wrapperObject->fetchAll ( $this->wrapperObject->_getStatement ( $sql ), $parameters, $mode );
119 return $this->wrapperObject->fetchOne ( $this->wrapperObject->_getStatement ( $sql ), $parameters, $mode );
123 return $this->wrapperObject->fetchAllColumn ( $this->wrapperObject->_getStatement ( $sql ), $parameters, $column );
127 $statement = $this->wrapperObject->_getStatement ( $sql );
128 if ($statement->execute ( $parameters )) {
129 Logger::info (
'Database', $sql,
'prepareAndFetchColumn', $parameters );
130 return $statement->fetchColumn ( $columnNumber );
141 return $this->wrapperObject->_getStatement ( $sql );
150 return $this->wrapperObject->_getStatement ( $sql );
171 return $this->wrapperObject->execute ( $sql );
181 return $this->wrapperObject->prepareStatement ( $sql );
192 return $this->wrapperObject->prepareNamedStatement ( $name, $sql );
203 return $this->wrapperObject->getNamedStatement ( $name, $sql );
215 return $this->wrapperObject->bindValueFromStatement ( $statement, $parameter, $value );
224 return $this->wrapperObject->lastInsertId ( $name );
233 public function count($tableName, $condition =
'') {
234 if ($condition !=
''){
235 $condition =
' WHERE ' . $condition;
237 return $this->wrapperObject->queryColumn (
'SELECT COUNT(*) FROM ' . $tableName . $condition );
241 return $this->wrapperObject->queryColumn ( $query, $columnNumber );
245 return $this->wrapperObject->queryAll ( $query, $mode );
249 return ($this->wrapperObject !==
null && $this->
ping ());
253 return ($this->wrapperObject && $this->wrapperObject->ping ());
Abstract class for database caching Ubiquity\cache\database$DbCache This class is part of Ubiquity.
lastInserId($name=null)
Returns the last insert id.
execute($sql)
Execute an SQL statement and return the number of affected rows (INSERT, UPDATE or DELETE)
prepareAndExecute($tableName, $condition, $fields, $parameters=null, $useCache=false, $one=false)
prepareAndExecuteUpdate($sql, $parameters=null)
Prepares a statement and execute a query for update (INSERT, UPDATE, DELETE...)
queryColumn($query, $columnNumber=null)
prepareAndFetchColumn($sql, $parameters=null, $columnNumber=0)
query($sql)
Executes an SQL statement, returning a result set as a statement object.
prepareStatement($sql)
Prepares a statement for execution and returns a statement object.
bindValueFromStatement($statement, $parameter, $value)
Sets $value to $parameter.
getCacheValue($tableName, $condition, $parameters, &$cKey)
_optExecuteAndFetch($statement, $tableName, $condition, $parameters=null, $useCache=false, $one=false)
_optExecuteAndFetchNoCache($statement, $parameters=null, $one=false)
count($tableName, $condition='')
Returns the number of records in $tableName matching with the condition passed as a parameter.
prepareAndExecuteNoCache($tableName, $condition, $fields, $parameters=null)
fetchAll($query, $mode=null)
prepareAndFetchAll($sql, $parameters=null, $mode=null)
getNamedStatement(string $name, ?string $sql=null)
Returns the statement corresponding to the name.
prepareAndFetchOne($sql, $parameters=null, $mode=null)
getDaoPreparedStatement($tableName, $condition, $fields)
prepareNamedStatement(string $name, string $sql)
Prepares and returns a statement for execution and gives it a name.
prepareAndFetchAllColumn($sql, $parameters=null, $column=null)
Abstract class for logging Ubiquity\log$Logger This class is part of Ubiquity.