Public Member Functions | |
connect ($dsninfo, $flags=0) | |
Connect to a database and log in as the specified user. | |
applyLimit (&$sql, $offset, $limit) | |
close () | |
executeQuery ($sql, $fetchmode=null) | |
executeUpdate ($sql) | |
getUpdateCount () | |
Gets the number of rows affected by the data manipulation query. | |
getDatabaseInfo () | |
getIdGenerator () | |
prepareStatement ($sql) | |
prepareCall ($sql) | |
createStatement () | |
Protected Member Functions | |
beginTrans () | |
Start a database transaction. | |
commitTrans () | |
Commit the current transaction. | |
rollbackTrans () | |
Roll back (undo) the current transaction. | |
Private Attributes | |
$result_affected_rows |
Definition at line 35 of file PgSQLConnection.php.
PgSQLConnection::applyLimit | ( | &$ | sql, | |
$ | offset, | |||
$ | limit | |||
) |
Implements Connection.
Definition at line 114 of file PgSQLConnection.php.
00115 { 00116 if ( $limit > 0 ) { 00117 $sql .= " LIMIT ".$limit; 00118 } 00119 if ( $offset > 0 ) { 00120 $sql .= " OFFSET ".$offset; 00121 } 00122 }
PgSQLConnection::beginTrans | ( | ) | [protected] |
Start a database transaction.
SQLException |
Reimplemented from ConnectionCommon.
Definition at line 168 of file PgSQLConnection.php.
References $result.
00169 { 00170 $result = @pg_query($this->dblink, "BEGIN"); 00171 if (!$result) { 00172 throw new SQLException('Could not begin transaction', pg_last_error($this->dblink)); 00173 } 00174 }
PgSQLConnection::close | ( | ) |
Implements Connection.
Definition at line 127 of file PgSQLConnection.php.
00128 { 00129 $ret = @pg_close($this->dblink); 00130 $this->result_affected_rows = null; 00131 $this->dblink = null; 00132 return $ret; 00133 }
PgSQLConnection::commitTrans | ( | ) | [protected] |
Commit the current transaction.
SQLException |
Reimplemented from ConnectionCommon.
Definition at line 181 of file PgSQLConnection.php.
References $result.
00182 { 00183 $result = @pg_query($this->dblink, "COMMIT"); 00184 if (!$result) { 00185 throw new SQLException('Could not commit transaction', pg_last_error($this->dblink)); 00186 } 00187 }
PgSQLConnection::connect | ( | $ | dsninfo, | |
$ | flags = 0 | |||
) |
Connect to a database and log in as the specified user.
array | $dsn The datasource hash. | |
$flags | Any connection flags. public |
SQLException |
Implements Connection.
Definition at line 55 of file PgSQLConnection.php.
References ConnectionCommon::$flags, and Creole::PERSISTENT.
00056 { 00057 global $php_errormsg; 00058 00059 if (!extension_loaded('pgsql')) { 00060 throw new SQLException('pgsql extension not loaded'); 00061 } 00062 00063 $this->dsn = $dsninfo; 00064 $this->flags = $flags; 00065 00066 $persistent = ($flags & Creole::PERSISTENT === Creole::PERSISTENT); 00067 00068 $protocol = (isset($dsninfo['protocol'])) ? $dsninfo['protocol'] : 'tcp'; 00069 $connstr = ''; 00070 00071 if ($protocol == 'tcp') { 00072 if (!empty($dsninfo['hostspec'])) { 00073 $connstr = 'host=' . $dsninfo['hostspec']; 00074 } 00075 if (!empty($dsninfo['port'])) { 00076 $connstr .= ' port=' . $dsninfo['port']; 00077 } 00078 } 00079 00080 if (isset($dsninfo['database'])) { 00081 $connstr .= ' dbname=\'' . addslashes($dsninfo['database']) . '\''; 00082 } 00083 if (!empty($dsninfo['username'])) { 00084 $connstr .= ' user=\'' . addslashes($dsninfo['username']) . '\''; 00085 } 00086 if (!empty($dsninfo['password'])) { 00087 $connstr .= ' password=\'' . addslashes($dsninfo['password']) . '\''; 00088 } 00089 if (!empty($dsninfo['options'])) { 00090 $connstr .= ' options=' . $dsninfo['options']; 00091 } 00092 if (!empty($dsninfo['tty'])) { 00093 $connstr .= ' tty=' . $dsninfo['tty']; 00094 } 00095 00096 if ($persistent) { 00097 $conn = @pg_pconnect($connstr); 00098 } else { 00099 $conn = @pg_connect($connstr); 00100 } 00101 00102 if (!$conn) { 00103 // hide the password from connstr 00104 $cleanconnstr = preg_replace('/password=\'.*?\'($|\s)/', 'password=\'*********\'', $connstr); 00105 throw new SQLException('Could not connect', $php_errormsg, $cleanconnstr); 00106 } 00107 00108 $this->dblink = $conn; 00109 }
PgSQLConnection::createStatement | ( | ) |
Implements Connection.
Definition at line 254 of file PgSQLConnection.php.
00255 { 00256 require_once 'creole/drivers/pgsql/PgSQLStatement.php'; 00257 return new PgSQLStatement($this); 00258 }
PgSQLConnection::executeQuery | ( | $ | sql, | |
$ | fetchmode = null | |||
) |
Implements Connection.
Definition at line 138 of file PgSQLConnection.php.
References $result.
00139 { 00140 $result = @pg_query($this->dblink, $sql); 00141 if (!$result) { 00142 throw new SQLException('Could not execute query', pg_last_error($this->dblink), $sql); 00143 } 00144 $this->result_affected_rows = (int) @pg_affected_rows($result); 00145 00146 return new PgSQLResultSet($this, $result, $fetchmode); 00147 }
PgSQLConnection::executeUpdate | ( | $ | sql | ) |
Implements Connection.
Definition at line 152 of file PgSQLConnection.php.
References $result.
00153 { 00154 $result = @pg_query($this->dblink, $sql); 00155 if (!$result) { 00156 throw new SQLException('Could not execute update', pg_last_error($this->dblink), $sql); 00157 } 00158 $this->result_affected_rows = (int) @pg_affected_rows($result); 00159 00160 return $this->result_affected_rows; 00161 }
PgSQLConnection::getDatabaseInfo | ( | ) |
Implements Connection.
Definition at line 220 of file PgSQLConnection.php.
00221 { 00222 require_once 'creole/drivers/pgsql/metadata/PgSQLDatabaseInfo.php'; 00223 return new PgSQLDatabaseInfo($this); 00224 }
PgSQLConnection::getIdGenerator | ( | ) |
Implements Connection.
Definition at line 229 of file PgSQLConnection.php.
00230 { 00231 require_once 'creole/drivers/pgsql/PgSQLIdGenerator.php'; 00232 return new PgSQLIdGenerator($this); 00233 }
PgSQLConnection::getUpdateCount | ( | ) |
Gets the number of rows affected by the data manipulation query.
Implements Connection.
Definition at line 208 of file PgSQLConnection.php.
00209 { 00210 if ( $this->result_affected_rows === null ) { 00211 throw new SQLException('getUpdateCount called before any sql queries were executed'); 00212 } 00213 return $this->result_affected_rows; 00214 }
PgSQLConnection::prepareCall | ( | $ | sql | ) |
Reimplemented from ConnectionCommon.
Definition at line 247 of file PgSQLConnection.php.
00247 { 00248 throw new SQLException('PostgreSQL does not support stored procedures.'); 00249 }
PgSQLConnection::prepareStatement | ( | $ | sql | ) |
Implements Connection.
Definition at line 238 of file PgSQLConnection.php.
00239 { 00240 require_once 'creole/drivers/pgsql/PgSQLPreparedStatement.php'; 00241 return new PgSQLPreparedStatement($this, $sql); 00242 }
PgSQLConnection::rollbackTrans | ( | ) | [protected] |
Roll back (undo) the current transaction.
SQLException |
Reimplemented from ConnectionCommon.
Definition at line 194 of file PgSQLConnection.php.
References $result.
00195 { 00196 $result = @pg_query($this->dblink, "ROLLBACK"); 00197 if (!$result) { 00198 throw new SQLException('Could not rollback transaction', pg_last_error($this->dblink)); 00199 } 00200 }
PgSQLConnection::$result_affected_rows [private] |
Definition at line 44 of file PgSQLConnection.php.