16 private $dbConnection;
18 public function __construct($dbConnection)
20 $this->dbConnection = $dbConnection;
32 if ($namedatalen >= strlen($stmt)) {
35 $hash = substr($stmt, 0, $namedatalen);
36 for ($i = $namedatalen; $i < strlen($stmt); $i ++) {
37 $hash[$i%$namedatalen] = chr((ord($hash[$i%$namedatalen])+ord($stmt[$i])-32)%96+32);
47 public function prepare($statementName, $sqlStatement)
49 return pg_prepare($this->dbConnection, $this->
identifierHash($statementName), $sqlStatement);
57 public function execute($statementName, $parameters)
59 return pg_execute($this->dbConnection, $this->
identifierHash($statementName), $parameters);
66 public function query($sqlStatement)
68 return pg_query($this->dbConnection, $sqlStatement);
76 return pg_connection_status($this->dbConnection) === PGSQL_CONNECTION_OK;
84 return pg_last_error($this->dbConnection);
93 return pg_free_result($res);
102 return pg_fetch_array($res,
null, PGSQL_ASSOC);
111 if (pg_num_rows($res) == 0) {
114 return pg_fetch_all($res);
122 pg_query($this->dbConnection,
"BEGIN");
131 pg_query($this->dbConnection,
"COMMIT");
140 pg_query($this->dbConnection,
"ROLLBACK");
150 return $booleanValue ===
't';
159 return $booleanValue ?
't' :
'f';
168 return pg_escape_string($string);
178 $dbName = pg_dbname($this->dbConnection);
179 $sql =
"SELECT count(*) cnt
180 FROM information_schema.tables
181 WHERE table_catalog='$dbName'
182 AND table_name='". strtolower($tableName) .
"'";
183 $res = pg_query($this->dbConnection, $sql);
184 if (!$res && pg_connection_status($this->dbConnection) === PGSQL_CONNECTION_OK) {
185 throw new \Exception(pg_last_error($this->dbConnection));
187 throw new \Exception(
'DB connection lost');
189 $row = pg_fetch_assoc($res);
190 pg_free_result($res);
191 return($row[
'cnt']>0);
202 $dbName = pg_dbname($this->dbConnection);
203 $sql =
"SELECT count(*) cnt
204 FROM information_schema.columns
205 WHERE table_catalog='$dbName'
206 AND table_name='". strtolower($tableName) .
"'
207 AND column_name='". strtolower($columnName) .
"'";
208 $res = pg_query($this->dbConnection, $sql);
209 if (!$res && pg_connection_status($this->dbConnection) === PGSQL_CONNECTION_OK) {
210 throw new \Exception(pg_last_error($this->dbConnection));
212 throw new \Exception(
'DB connection lost');
214 $row = pg_fetch_assoc($res);
215 pg_free_result($res);
216 return($row[
'cnt']>0);
228 $sql .=
" RETURNING $colName";
229 $stmt .=
".returning:$colName";
231 $res = $this->
execute($stmt,$params);
234 return $return[$colName];
insertPreparedAndReturn($stmt, $sql, $params, $colName)
existsColumn($tableName, $columnName)
execute($statementName, $parameters)
booleanToDb($booleanValue)
prepare($statementName, $sqlStatement)
identifierHash($stmt)
PostgreSQL uses no more than NAMEDATALEN-1 characters of an identifier; hence long statementNames nee...
booleanFromDb($booleanValue)