Permalink
Browse files

Removes useless call of function_exists since we are PHP5+ only

  • Loading branch information...
1 parent 0e8c2bf commit 24f83bb50f41ad95d320e241ac0de58eec7a5367 @ioguix ioguix committed Jun 3, 2011
@@ -51,13 +51,9 @@ function Connection($host, $port, $sslmode, $user, $password, $database, $fetchM
* @return -3 Database-specific failure
*/
function getDriver(&$description) {
- // If we're on a recent enough PHP 5, and against PostgreSQL 7.4 or
- // higher, we don't need to query for the version. This gives a great
- // speed up.
- if (function_exists('pg_version')) {
- $v = pg_version($this->conn->_connectionID);
- if (isset($v['server'])) $version = $v['server'];
- }
+
+ $v = pg_version($this->conn->_connectionID);
+ if (isset($v['server'])) $version = $v['server'];
// If we didn't manage to get the version without a query, query...
if (!isset($version)) {
@@ -105,10 +101,7 @@ function getDriver(&$description) {
* @return Error string
*/
function getLastError() {
- if (function_exists('pg_errormessage'))
- return pg_errormessage($this->conn->_connectionID);
- else
- return pg_last_error($this->conn->_connectionID);
+ return pg_last_error($this->conn->_connectionID);
}
}
@@ -183,10 +183,7 @@ function Postgres($conn) {
function clean(&$str) {
if ($str === null) return null;
$str = str_replace("\r\n","\n",$str);
- if (function_exists('pg_escape_string'))
- $str = pg_escape_string($str);
- else
- $str = addslashes($str);
+ $str = pg_escape_string($str);
return $str;
}
@@ -222,10 +219,7 @@ function fieldArrayClean(&$arr) {
function arrayClean(&$arr) {
foreach ($arr as $k => $v) {
if ($v === null) continue;
- if (function_exists('pg_escape_string'))
- $arr[$k] = pg_escape_string($v);
- else
- $arr[$k] = addslashes($v);
+ $arr[$k] = pg_escape_string($v);
}
return $arr;
}
@@ -236,12 +230,7 @@ function arrayClean(&$arr) {
* @return Data formatted for on-screen display
*/
function escapeBytea($data) {
- if (function_exists('pg_escape_bytea'))
- return stripslashes(pg_escape_bytea($data));
- else {
- $translations = array('\\a' => '\\007', '\\b' => '\\010', '\\t' => '\\011', '\\n' => '\\012', '\\v' => '\\013', '\\f' => '\\014', '\\r' => '\\015');
- return strtr(addCSlashes($data, "\0..\37\177..\377"), $translations);
- }
+ return stripslashes(pg_escape_bytea($data));
}
/**
@@ -518,27 +507,14 @@ function getDatabaseOwner($database) {
* @return The encoding. eg. SQL_ASCII, UTF-8, etc.
*/
function getDatabaseEncoding() {
- // Try to avoid a query if at all possible (5)
- if (function_exists('pg_parameter_status')) {
- $encoding = pg_parameter_status($this->conn->_connectionID, 'server_encoding');
- if ($encoding !== false) return $encoding;
- }
-
- $sql = "SELECT getdatabaseencoding() AS encoding";
-
- return $this->selectField($sql, 'encoding');
+ return pg_parameter_status($this->conn->_connectionID, 'server_encoding');
}
/**
* Returns the current default_with_oids setting
* @return default_with_oids setting
*/
function getDefaultWithOid() {
- // Try to avoid a query if at all possible (5)
- if (function_exists('pg_parameter_status')) {
- $default = pg_parameter_status($this->conn->_connectionID, 'default_with_oids');
- if ($default !== false) return $default;
- }
$sql = "SHOW default_with_oids";
@@ -7552,12 +7528,10 @@ function executeScript($name, $callback = null) {
$query_buf .= $subline;
$query_buf .= ';';
- // Execute the query (supporting 4.1.x PHP...). PHP cannot execute
+ // Execute the query. PHP cannot execute
// empty queries, unlike libpq
- if (function_exists('pg_query'))
- $res = @pg_query($conn, $query_buf);
- else
- $res = @pg_exec($conn, $query_buf);
+ $res = @pg_query($conn, $query_buf);
+
// Call the callback function for display
if ($callback !== null) $callback($query_buf, $res, $lineno);
// Check for COPY request
@@ -7578,7 +7552,7 @@ function executeScript($name, $callback = null) {
$query_start = $i + $thislen;
}
- /*
+ /*
* keyword or identifier?
* We grab the whole string so that we don't
* mistakenly see $foo$ inside an identifier as the start
@@ -7617,11 +7591,9 @@ function executeScript($name, $callback = null) {
*/
if (strlen($query_buf) > 0 && strspn($query_buf, " \t\n\r") != strlen($query_buf))
{
- // Execute the query (supporting 4.1.x PHP...)
- if (function_exists('pg_query'))
- $res = @pg_query($conn, $query_buf);
- else
- $res = @pg_exec($conn, $query_buf);
+ // Execute the query
+ $res = @pg_query($conn, $query_buf);
+
// Call the callback function for display
if ($callback !== null) $callback($query_buf, $res, $lineno);
// Check for COPY request
@@ -251,8 +251,6 @@ function findObject($term, $filter) {
return $this->selectSet($sql);
}
- // Database functions
-
/**
* Returns table locks information in the current database
* @return A recordset
@@ -273,6 +271,16 @@ function getLocks() {
return $this->selectSet($sql);
}
+ /**
+ * Returns the current database encoding
+ * @return The encoding. eg. SQL_ASCII, UTF-8, etc.
+ */
+ function getDatabaseEncoding() {
+ $sql = "SELECT getdatabaseencoding() AS encoding";
+
+ return $this->selectField($sql, 'encoding');
+ }
+
// Table functions
/**
@@ -7,13 +7,6 @@
###TODO: Better documentation!!!
-// Compatibility functions:
-if (!function_exists('is_a')) {
- function is_a($object, $class) {
- return is_object($object) && get_class($object) == strtolower($class) || is_subclass_of($object, $class);
- }
-}
-
// Construction functions:
function field($fieldName, $default = null) {
View
@@ -225,12 +225,7 @@
// Set client encoding to database encoding
if ($dbEncoding != '') {
// Explicitly change client encoding if it's different to server encoding.
- if (function_exists('pg_client_encoding'))
- $currEncoding = pg_client_encoding($data->conn->_connectionID);
- elseif (function_exists('pg_clientencoding'))
- $currEncoding = pg_clientencoding($data->conn->_connectionID);
- else
- $currEncoding = null;
+ $currEncoding = pg_client_encoding($data->conn->_connectionID);
if ($currEncoding != $dbEncoding) {
$status = $data->setClientEncoding($dbEncoding);

0 comments on commit 24f83bb

Please sign in to comment.