Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
AbstractDbWrapper.php
Go to the documentation of this file.
1<?php
2
4
6
15abstract class AbstractDbWrapper {
16 protected $dbInstance;
17 protected $statements;
18 protected $operations=[
19 DbOperations::CREATE_DATABASE=>'CREATE DATABASE {name}',
20 DbOperations::CREATE_TABLE=>'CREATE TABLE {name} ({fields}) {attributes}',
21 DbOperations::SELECT_DB=>'USE {name}',
22 DbOperations::FIELD=>'{name} {type} {extra}',
23 DbOperations::ALTER_TABLE=>'ALTER TABLE {tableName} {alter}',
24 DbOperations::FOREIGN_KEY=>'ALTER TABLE {tableName} ADD CONSTRAINT {fkName} FOREIGN KEY ({fkFieldName}) REFERENCES {referencesTableName} ({referencesFieldName}) ON DELETE {onDelete} ON UPDATE {onUpdate}',
25 DbOperations::ALTER_TABLE_KEY=>'ALTER TABLE {tableName} ADD {type} KEY ({pkFields})',
26 DbOperations::AUTO_INC=>'ALTER TABLE {tableName} MODIFY {fieldName} AUTO_INCREMENT, AUTO_INCREMENT={value}',
27 DbOperations::MODIFY_FIELD=>'ALTER TABLE {tableName} MODIFY {fieldName} {attributes}',
28 DbOperations::ADD_FIELD=>'ALTER TABLE {tableName} ADD {fieldName} {attributes}'
29 ];
30
31 const PHP_TYPES = [ 'string' => true,'bool' => true,'float' => true,'int' => true ];
32
33 public $quote;
34
35 abstract public function query(string $sql);
36
37 abstract public function queryAll(string $sql, int $fetchStyle = null);
38
39 abstract public function queryColumn(string $sql, int $columnNumber = null);
40
41 abstract public static function getAvailableDrivers();
42
43 public function _getStatement(string $sql) {
44 return $this->statements [\md5 ( $sql )] ??= $this->getStatement ( $sql );
45 }
46
47 public function prepareNamedStatement(string $name, string $sql) {
48 return $this->statements [$name] = $this->getStatement ( $sql );
49 }
50
51 public function getNamedStatement(string $name, ?string $sql = null) {
52 return $this->statements [$name] ??= $this->getStatement ( $sql );
53 }
54
55 abstract public function getStatement(string $sql);
56
57 abstract public function connect(string $dbType, $dbName, $serverName, string $port, string $user, string $password, array $options);
58
59 abstract public function getDSN(string $serverName, string $port, string $dbName, string $dbType = 'mysql');
60
61 abstract public function execute(string $sql);
62
63 abstract public function prepareStatement(string $sql);
64
65 abstract public function executeStatement($statement, array $values = null);
66
67 abstract public function statementRowCount($statement);
68
69 abstract public function lastInsertId($name = null);
70
78 abstract public function bindValueFromStatement($statement, $parameter, $value);
79
80 abstract public function fetchColumn($statement, array $values = null, int $columnNumber = null);
81
82 abstract public function fetchAll($statement, array $values = null, $mode = null);
83
84 abstract public function fetchOne($statement, array $values = null, $mode = null);
85
86 abstract public function fetchAllColumn($statement, array $values = null, string $column = null);
87
88 abstract public function getTablesName();
89
90 abstract public function beginTransaction();
91
92 abstract public function commit();
93
94 abstract public function inTransaction();
95
96 abstract public function rollBack();
97
98 abstract public function nestable();
99
100 abstract public function savePoint($level);
101
102 abstract public function releasePoint($level);
103
104 abstract public function rollbackPoint($level);
105
106 abstract public function ping();
107
108 abstract public function getPrimaryKeys($tableName);
109
110 abstract public function getFieldsInfos($tableName);
111
112 abstract public function getForeignKeys($tableName, $pkName, $dbName = null);
113
114 abstract public function _optPrepareAndExecute($sql, array $values = null, $one = false);
115
116 public function _optExecuteAndFetch($statement, array $values = null, $one = false) {
117 }
118
119 abstract public function getRowNum(string $tableName, string $pkName, string $condition): int;
120
121 abstract public function groupConcat(string $fields, string $separator): string;
122
123 public function toStringOperator() {
124 return '';
125 }
126
127 public function close() {
128 $this->statements = [ ];
129 $this->dbInstance = null;
130 }
131
136 public function getDbInstance() {
137 return $this->dbInstance;
138 }
139
144 public function setDbInstance($dbInstance) {
145 $this->dbInstance = $dbInstance;
146 }
147
148 public function quoteValue($value, $type = 2) {
149 return "'" . \addslashes ( $value ) . "'";
150 }
151
159 public function getPHPType(string $dbType): string {
160 return '';
161 }
162
168 public function migrateOperation(string $operation):?string{
169 return $this->operations[$operation]??null;
170 }
171
177 public function setIsolationLevel($isolationLevel){
178 throw new DBException('The setIsolation level is not implemented for this wrapper');
179 }
180}
Ubiquity\db\providers$AbstractDbWrapper This class is part of Ubiquity.
executeStatement($statement, array $values=null)
fetchColumn($statement, array $values=null, int $columnNumber=null)
getDSN(string $serverName, string $port, string $dbName, string $dbType='mysql')
migrateOperation(string $operation)
Returns the SQL string for a migration operation.
getForeignKeys($tableName, $pkName, $dbName=null)
_optPrepareAndExecute($sql, array $values=null, $one=false)
groupConcat(string $fields, string $separator)
connect(string $dbType, $dbName, $serverName, string $port, string $user, string $password, array $options)
bindValueFromStatement($statement, $parameter, $value)
Used by DAO.
queryColumn(string $sql, int $columnNumber=null)
fetchAll($statement, array $values=null, $mode=null)
getRowNum(string $tableName, string $pkName, string $condition)
fetchAllColumn($statement, array $values=null, string $column=null)
getNamedStatement(string $name, ?string $sql=null)
fetchOne($statement, array $values=null, $mode=null)
_optExecuteAndFetch($statement, array $values=null, $one=false)
queryAll(string $sql, int $fetchStyle=null)
prepareNamedStatement(string $name, string $sql)