示例#1
0
 public static function castLink($link, array $a, Stub $stub, $isNested)
 {
     $a['status'] = pg_connection_status($link);
     $a['status'] = new ConstStub(PGSQL_CONNECTION_OK === $a['status'] ? 'PGSQL_CONNECTION_OK' : 'PGSQL_CONNECTION_BAD', $a['status']);
     $a['busy'] = pg_connection_busy($link);
     $a['transaction'] = pg_transaction_status($link);
     if (isset(self::$transactionStatus[$a['transaction']])) {
         $a['transaction'] = new ConstStub(self::$transactionStatus[$a['transaction']], $a['transaction']);
     }
     $a['pid'] = pg_get_pid($link);
     $a['last error'] = pg_last_error($link);
     $a['last notice'] = pg_last_notice($link);
     $a['host'] = pg_host($link);
     $a['port'] = pg_port($link);
     $a['dbname'] = pg_dbname($link);
     $a['options'] = pg_options($link);
     $a['version'] = pg_version($link);
     foreach (self::$paramCodes as $v) {
         if (false !== ($s = pg_parameter_status($link, $v))) {
             $a['param'][$v] = $s;
         }
     }
     $a['param']['client_encoding'] = pg_client_encoding($link);
     $a['param'] = new EnumStub($a['param']);
     return $a;
 }
示例#2
0
 public function connect()
 {
     if ($this->_connection) {
         return;
     }
     try {
         $this->_connection = empty($this->_config['connection']['persistent']) ? pg_connect($this->_config['connection']['info'], PGSQL_CONNECT_FORCE_NEW) : pg_pconnect($this->_config['connection']['info'], PGSQL_CONNECT_FORCE_NEW);
     } catch (ErrorException $e) {
         throw new Database_Exception(':error', array(':error' => $e->getMessage()));
     }
     if (!is_resource($this->_connection)) {
         throw new Database_Exception('Unable to connect to PostgreSQL ":name"', array(':name' => $this->_instance));
     }
     $this->_version = pg_parameter_status($this->_connection, 'server_version');
     if (!empty($this->_config['charset'])) {
         $this->set_charset($this->_config['charset']);
     }
     if (empty($this->_config['schema'])) {
         // Assume the default schema without changing the search path
         $this->_config['schema'] = 'public';
     } else {
         if (!pg_send_query($this->_connection, 'SET search_path = ' . $this->_config['schema'] . ', pg_catalog')) {
             throw new Database_Exception(pg_last_error($this->_connection));
         }
         if (!($result = pg_get_result($this->_connection))) {
             throw new Database_Exception(pg_last_error($this->_connection));
         }
         if (pg_result_status($result) !== PGSQL_COMMAND_OK) {
             throw new Database_Exception(pg_result_error($result));
         }
     }
 }
示例#3
0
 /**
  * Connect to server
  */
 function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)
 {
     $connect_string = '';
     if ($sqluser) {
         $connect_string .= "user={$sqluser} ";
     }
     if ($sqlpassword) {
         $connect_string .= "password={$sqlpassword} ";
     }
     if ($sqlserver) {
         if (strpos($sqlserver, ':') !== false) {
             list($sqlserver, $port) = explode(':', $sqlserver);
         }
         if ($sqlserver !== 'localhost') {
             $connect_string .= "host={$sqlserver} ";
         }
         if ($port) {
             $connect_string .= "port={$port} ";
         }
     }
     $schema = '';
     if ($database) {
         $this->dbname = $database;
         if (strpos($database, '.') !== false) {
             list($database, $schema) = explode('.', $database);
         }
         $connect_string .= "dbname={$database}";
     }
     $this->persistency = $persistency;
     $this->db_connect_id = $this->persistency ? @pg_pconnect($connect_string, $new_link) : @pg_connect($connect_string, $new_link);
     if ($this->db_connect_id) {
         // determine what version of PostgreSQL is running, we can be more efficient if they are running 8.2+
         if (version_compare(PHP_VERSION, '5.0.0', '>=')) {
             $this->pgsql_version = @pg_parameter_status($this->db_connect_id, 'server_version');
         } else {
             $query_id = @pg_query($this->db_connect_id, 'SELECT VERSION()');
             $row = @pg_fetch_assoc($query_id, null);
             @pg_free_result($query_id);
             if (!empty($row['version'])) {
                 $this->pgsql_version = substr($row['version'], 10);
             }
         }
         if (!empty($this->pgsql_version) && $this->pgsql_version[0] >= '8' && $this->pgsql_version[2] >= '2') {
             $this->multi_insert = true;
         }
         if ($schema !== '') {
             @pg_query($this->db_connect_id, 'SET search_path TO ' . $schema);
         }
         return $this->db_connect_id;
     }
     return $this->sql_error('');
 }
示例#4
0
 public function get_versions()
 {
     $version['engine'] = 'PostgreSQL';
     $version['client'] = 'N/A';
     $version['server'] = 'N/A';
     $version = array_merge($version, pg_version($this->_owner->connect_id));
     if ($version['server'] == 'N/A') {
         //pgsql not compiled into php
         $version['server'] = pg_parameter_status('server_version');
         //pgsql 7.4+
     }
     return $version;
 }
示例#5
0
 function get_versions()
 {
     $version['engine'] = 'PostgreSQL';
     $version['client'] = 'N/A';
     $version['server'] = 'N/A';
     if (function_exists('pg_version')) {
         //php5+
         $version = array_merge($version, pg_version($this->_owner->connect_id));
         if ($version['server'] == 'N/A') {
             //pgsql not compiled into php
             $version['server'] = pg_parameter_status('server_version');
             //pgsql 7.4+
         }
     } else {
         if ($result = pg_query($this->_owner->connect_id, 'SELECT VERSION()')) {
             list($v) = pg_fetch_row($result);
             pg_free_result($result);
             if (!empty($v)) {
                 $version['server'] = preg_replace('#PostgreSQL ([0-9\\.]+).*#i', '\\1', $v);
             }
         }
     }
     return $version;
 }
示例#6
0
 /**
  * Determines whether or not a user is a super user
  * @param $username The username of the user
  * @return True if is a super user, false otherwise
  */
 function isSuperUser($username = '')
 {
     $this->clean($username);
     if (empty($usename)) {
         $val = pg_parameter_status($this->conn->_connectionID, 'is_superuser');
         if ($val !== false) {
             return $val == 'on';
         }
     }
     $sql = "SELECT usesuper FROM pg_user WHERE usename='{$username}'";
     $usesuper = $this->selectField($sql, 'usesuper');
     if ($usesuper == -1) {
         return false;
     } else {
         return $usesuper == 't';
     }
 }
 /**
  * Public method:
  *	Quotes correctly a string for this database
  *       	this->getAttribute( $attribute:Integer ):Mixed
  * @Param	Integer		a constant [	PDO_ATTR_SERVER_INFO,
  * 						PDO_ATTR_SERVER_VERSION,
  *                                              PDO_ATTR_CLIENT_VERSION,
  *                                              PDO_ATTR_PERSISTENT	]
  * @Return	Mixed		correct information or false
  */
 function getAttribute($attribute)
 {
     $result = false;
     switch ($attribute) {
         case PDO_ATTR_SERVER_INFO:
             $result = pg_parameter_status($this->__connection, 'server_encoding');
             break;
         case PDO_ATTR_SERVER_VERSION:
             $result = pg_parameter_status($this->__connection, 'server_version');
             break;
         case PDO_ATTR_CLIENT_VERSION:
             $result = pg_parameter_status($this->__connection, 'server_version');
             $result .= ' ' . pg_parameter_status($this->__connection, 'client_encoding');
             break;
         case PDO_ATTR_PERSISTENT:
             $result = $this->__persistent;
             break;
     }
     return $result;
 }
 public function testRangeTypeConverterFromMetadata()
 {
     if (!TESTS_SAD_SPIRIT_PG_WRAPPER_CONNECTION_STRING) {
         $this->markTestSkipped('Connection string is not configured');
     }
     $connection = new Connection(TESTS_SAD_SPIRIT_PG_WRAPPER_CONNECTION_STRING, false);
     if (version_compare(pg_parameter_status($connection->getResource(), 'server_version'), '9.2.0', '<')) {
         $this->markTestSkipped('Connection to PostgreSQL 9.2+ required');
     }
     $connection->setTypeConverterFactory($this->factory);
     $connection->execute("drop type if exists textrange");
     $connection->execute("create type textrange as range (subtype=text, collation=\"C\")");
     $this->assertEquals(new RangeConverter(new StringConverter()), $this->factory->getConverter('textrange'));
 }
示例#9
0
 /**
  * check postgres serversion. at least 8.2 required
  *
  * @return mixed bool true if successful, false if unknown version, else server_version
  */
 public function check_postgres_version()
 {
     $server_version = pg_parameter_status($this->dbconn, "server_version");
     if (false !== $server_version) {
         if (-1 == version_compare($server_version, "8.2")) {
             return $server_version;
         }
         // version ok
         return true;
     }
     // unknown server_version
     return false;
 }
示例#10
0
 public function getAttribute($attribute, &$source = null, $func = 'PDO::getAttribute', &$last_error = null)
 {
     switch ($attribute) {
         case PDO::ATTR_AUTOCOMMIT:
             return $this->autocommit;
             break;
         case PDO::ATTR_CLIENT_VERSION:
             $ver = pg_version($this->link);
             return $ver['client'];
             break;
         case PDO::ATTR_CONNECTION_STATUS:
             if (pg_connection_status($this->link) === PGSQL_CONNECTION_OK) {
                 return 'Connection OK; waiting to send.';
             } else {
                 return 'Connection BAD';
             }
             break;
         case PDO::ATTR_SERVER_INFO:
             return sprintf('PID: %d; Client Encoding: %s; Is Superuser: %s; Session Authorization: %s; Date Style: %s', pg_get_pid($this->link), pg_client_encoding($this->link), pg_parameter_status($this->link, 'is_superuser'), pg_parameter_status($this->link, 'session_authorization'), pg_parameter_status($this->link, 'DateStyle'));
             break;
         case PDO::ATTR_SERVER_VERSION:
             return pg_parameter_status($this->link, 'server_version');
             break;
         default:
             return parent::getAttribute($attribute, $source, $func, $last_error);
             break;
     }
 }
    /**
     * Populates the types list from pg_catalog.pg_type table
     *
     * @param bool $force Force loading from database even if cached list is available
     * @throws exceptions\InvalidQueryException
     */
    private function _loadTypes($force = false)
    {
        $cacheKey = $this->_connection->getConnectionId() . '-types';
        if (!($cache = $this->_connection->getMetadataCache()) || $force || null === ($this->_dbTypes = $cache->getItem($cacheKey))) {
            $this->_dbTypes = array('composite' => array(), 'array' => array(), 'range' => array(), 'names' => array());
            $sql = <<<SQL
    select t.oid, nspname, typname, typarray, typrelid
    from pg_catalog.pg_type as t, pg_catalog.pg_namespace as s
    where t.typnamespace = s.oid and
          typtype != 'd'
    order by 4 desc
SQL;
            if (!($res = @pg_query($this->_connection->getResource(), $sql))) {
                throw new exceptions\InvalidQueryException(pg_last_error($this->_connection->getResource()));
            }
            while ($row = pg_fetch_assoc($res)) {
                if (!isset($this->_dbTypes['names'][$row['typname']])) {
                    $this->_dbTypes['names'][$row['typname']] = array($row['nspname'] => $row['oid']);
                } else {
                    $this->_dbTypes['names'][$row['typname']][$row['nspname']] = $row['oid'];
                }
                if ('0' !== $row['typarray']) {
                    $this->_dbTypes['array'][$row['typarray']] = $row['oid'];
                }
                if ('0' !== $row['typrelid']) {
                    $this->_dbTypes['composite'][$row['oid']] = $row['typrelid'];
                }
            }
            pg_free_result($res);
            if (version_compare(pg_parameter_status($this->_connection->getResource(), 'server_version'), '9.2.0', '>=')) {
                if (!($res = @pg_query($this->_connection->getResource(), "select rngtypid, rngsubtype from pg_range"))) {
                    throw new exceptions\InvalidQueryException(pg_last_error($this->_connection->getResource()));
                }
                while ($row = pg_fetch_assoc($res)) {
                    $this->_dbTypes['range'][$row['rngtypid']] = $row['rngsubtype'];
                }
            }
            if ($cache) {
                $cache->setItem($cacheKey, $this->_dbTypes);
            }
        }
        $this->_oidMap = array();
        foreach ($this->_dbTypes['names'] as $typeName => $schemas) {
            foreach ($schemas as $schemaName => $oid) {
                $this->_oidMap[$oid] = array($schemaName, $typeName);
            }
        }
    }
 protected function inputNotNull($native)
 {
     foreach ($this->getFormats($this->_style) as $format) {
         if ($value = \DateTime::createFromFormat('!' . $format, $native)) {
             return $value;
         }
     }
     // check whether datestyle setting changed
     if ($this->_connection && $this->_style !== ($style = pg_parameter_status($this->_connection, 'DateStyle'))) {
         $this->_style = $style;
         foreach ($this->getFormats($this->_style) as $format) {
             if ($value = \DateTime::createFromFormat('!' . $format, $native)) {
                 return $value;
             }
         }
     }
     throw TypeConversionException::unexpectedValue($this, 'input', $this->expectation, $native);
 }
示例#13
0
 public function setConnectionResource($resource)
 {
     $this->_connection = $resource;
     // if connection was made to PostgreSQL 9.0+, then use 'hex' encoding
     $this->useHexEncoding(version_compare(pg_parameter_status($resource, 'server_version'), '9.0.0', '>='));
 }
示例#14
0
 public function getVersion()
 {
     return @pg_parameter_status($this->_hMaster, 'server_version');
 }
示例#15
0
 public function db_version($handle)
 {
     if (is_resource($handle)) {
         return pg_parameter_status($handle, 'server_version');
     }
     return null;
 }
示例#16
0
文件: pgsql.php 项目: phpontrax/trax
 /**
  * Do the grunt work of connecting to the database
  *
  * @return mixed connection resource on success, MDB2 Error Object on failure
  * @access protected
  */
 function _doConnect($username, $password, $database_name, $persistent = false)
 {
     if (!PEAR::loadExtension($this->phptype)) {
         return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 'extension ' . $this->phptype . ' is not compiled into PHP', __FUNCTION__);
     }
     if ($database_name == '') {
         $database_name = 'template1';
     }
     $protocol = $this->dsn['protocol'] ? $this->dsn['protocol'] : 'tcp';
     $params = array('');
     if ($protocol == 'tcp') {
         if ($this->dsn['hostspec']) {
             $params[0] .= 'host=' . $this->dsn['hostspec'];
         }
         if ($this->dsn['port']) {
             $params[0] .= ' port=' . $this->dsn['port'];
         }
     } elseif ($protocol == 'unix') {
         // Allow for pg socket in non-standard locations.
         if ($this->dsn['socket']) {
             $params[0] .= 'host=' . $this->dsn['socket'];
         }
         if ($this->dsn['port']) {
             $params[0] .= ' port=' . $this->dsn['port'];
         }
     }
     if ($database_name) {
         $params[0] .= ' dbname=\'' . addslashes($database_name) . '\'';
     }
     if ($username) {
         $params[0] .= ' user=\'' . addslashes($username) . '\'';
     }
     if ($password) {
         $params[0] .= ' password=\'' . addslashes($password) . '\'';
     }
     if (!empty($this->dsn['options'])) {
         $params[0] .= ' options=' . $this->dsn['options'];
     }
     if (!empty($this->dsn['tty'])) {
         $params[0] .= ' tty=' . $this->dsn['tty'];
     }
     if (!empty($this->dsn['connect_timeout'])) {
         $params[0] .= ' connect_timeout=' . $this->dsn['connect_timeout'];
     }
     if (!empty($this->dsn['sslmode'])) {
         $params[0] .= ' sslmode=' . $this->dsn['sslmode'];
     }
     if (!empty($this->dsn['service'])) {
         $params[0] .= ' service=' . $this->dsn['service'];
     }
     if ($this->_isNewLinkSet()) {
         if (version_compare(phpversion(), '4.3.0', '>=')) {
             $params[] = PGSQL_CONNECT_FORCE_NEW;
         }
     }
     $connect_function = $persistent ? 'pg_pconnect' : 'pg_connect';
     $connection = @call_user_func_array($connect_function, $params);
     if (!$connection) {
         return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null, 'unable to establish a connection', __FUNCTION__);
     }
     if (empty($this->dsn['disable_iso_date'])) {
         if (!@pg_query($connection, "SET SESSION DATESTYLE = 'ISO'")) {
             return $this->raiseError(null, null, null, 'Unable to set date style to iso', __FUNCTION__);
         }
     }
     if (!empty($this->dsn['charset'])) {
         $result = $this->setCharset($this->dsn['charset'], $connection);
         if (PEAR::isError($result)) {
             return $result;
         }
     }
     // Enable extra compatibility settings on 8.2 and later
     if (function_exists('pg_parameter_status')) {
         $version = pg_parameter_status($connection, 'server_version');
         if ($version == false) {
             return $this->raiseError(null, null, null, 'Unable to retrieve server version', __FUNCTION__);
         }
         $version = explode('.', $version);
         if ($version['0'] > 8 || $version['0'] == 8 && $version['1'] >= 2) {
             if (!@pg_query($connection, "SET SESSION STANDARD_CONFORMING_STRINGS = OFF")) {
                 return $this->raiseError(null, null, null, 'Unable to set standard_conforming_strings to off', __FUNCTION__);
             }
             if (!@pg_query($connection, "SET SESSION ESCAPE_STRING_WARNING = OFF")) {
                 return $this->raiseError(null, null, null, 'Unable to set escape_string_warning to off', __FUNCTION__);
             }
         }
     }
     return $connection;
 }
示例#17
0
 /**
  * Returns list of tables.
  * @return array
  */
 public function getTables()
 {
     $version = pg_parameter_status($this->resource, 'server_version');
     if ($version < 7.4) {
         throw new DibiDriverException('Reflection requires PostgreSQL 7.4 and newer.');
     }
     $res = $this->query("\r\n\t\t\tSELECT\r\n\t\t\t\ttable_name AS name,\r\n\t\t\t\tCASE table_type\r\n\t\t\t\t\tWHEN 'VIEW' THEN 1\r\n\t\t\t\t\tELSE 0\r\n\t\t\t\tEND AS view\r\n\t\t\tFROM\r\n\t\t\t\tinformation_schema.tables\r\n\t\t\tWHERE\r\n\t\t\t\ttable_schema = current_schema()\r\n\t\t");
     $tables = pg_fetch_all($res->resultSet);
     return $tables ? $tables : array();
 }
示例#18
0
/**
 * Creates global database connection.
 *
 * @param string $error returns a message in case of an error
 * @param bool   $debug turns On or Off trace calls when making connections. Suggested debug mode Off during Zabbix setup
 *
 * @return bool
 */
function DBconnect(&$error)
{
    global $DB;
    if (isset($DB['DB'])) {
        $error = _('Cannot create another database connection.');
        return false;
    }
    $result = true;
    $DB['DB'] = null;
    // global db handler
    $DB['TRANSACTIONS'] = 0;
    // level of a nested transation
    $DB['TRANSACTION_NO_FAILED_SQLS'] = true;
    // true - if no statements failed in transaction, false - there are failed statements
    $DB['SELECT_COUNT'] = 0;
    // stats
    $DB['EXECUTE_COUNT'] = 0;
    if (!isset($DB['TYPE'])) {
        $error = 'Unknown database type.';
        $result = false;
    } else {
        $DB['TYPE'] = strtoupper($DB['TYPE']);
        switch ($DB['TYPE']) {
            case ZBX_DB_MYSQL:
                $DB['DB'] = @mysqli_connect($DB['SERVER'], $DB['USER'], $DB['PASSWORD'], $DB['DATABASE'], $DB['PORT']);
                if (!$DB['DB']) {
                    $error = 'Error connecting to database: ' . trim(mysqli_connect_error());
                    $result = false;
                } else {
                    DBexecute('SET NAMES utf8');
                }
                if ($result) {
                    $dbBackend = new MysqlDbBackend();
                }
                break;
            case ZBX_DB_POSTGRESQL:
                $pg_connection_string = (!empty($DB['SERVER']) ? 'host=\'' . pg_connect_escape($DB['SERVER']) . '\' ' : '') . 'dbname=\'' . pg_connect_escape($DB['DATABASE']) . '\' ' . (!empty($DB['USER']) ? 'user=\'' . pg_connect_escape($DB['USER']) . '\' ' : '') . (!empty($DB['PASSWORD']) ? 'password=\'' . pg_connect_escape($DB['PASSWORD']) . '\' ' : '') . (!empty($DB['PORT']) ? 'port=' . pg_connect_escape($DB['PORT']) : '');
                $DB['DB'] = @pg_connect($pg_connection_string);
                if (!$DB['DB']) {
                    $error = 'Error connecting to database.';
                    $result = false;
                } else {
                    $schemaSet = DBexecute('SET search_path = ' . zbx_dbstr($DB['SCHEMA'] ? $DB['SCHEMA'] : 'public'), true);
                    if (!$schemaSet) {
                        clear_messages();
                        $error = pg_last_error();
                        $result = false;
                    } else {
                        if (false !== ($pgsql_version = pg_parameter_status('server_version'))) {
                            if ((int) $pgsql_version >= 9) {
                                // change the output format for values of type bytea from hex (the default) to escape
                                DBexecute('SET bytea_output = escape');
                            }
                        }
                    }
                }
                if ($result) {
                    $dbBackend = new PostgresqlDbBackend();
                }
                break;
            case ZBX_DB_ORACLE:
                $connect = '';
                if (!empty($DB['SERVER'])) {
                    $connect = '//' . $DB['SERVER'];
                    if ($DB['PORT'] != '0') {
                        $connect .= ':' . $DB['PORT'];
                    }
                    if ($DB['DATABASE']) {
                        $connect .= '/' . $DB['DATABASE'];
                    }
                }
                $DB['DB'] = @oci_connect($DB['USER'], $DB['PASSWORD'], $connect);
                if ($DB['DB']) {
                    DBexecute('ALTER SESSION SET NLS_NUMERIC_CHARACTERS=' . zbx_dbstr('. '));
                } else {
                    $ociError = oci_error();
                    $error = 'Error connecting to database: ' . $ociError['message'];
                    $result = false;
                }
                if ($result) {
                    $dbBackend = new OracleDbBackend();
                }
                break;
            case ZBX_DB_DB2:
                $connect = '';
                $connect .= 'DATABASE=' . $DB['DATABASE'] . ';';
                $connect .= 'HOSTNAME=' . $DB['SERVER'] . ';';
                $connect .= 'PORT=' . $DB['PORT'] . ';';
                $connect .= 'PROTOCOL=TCPIP;';
                $connect .= 'UID=' . $DB['USER'] . ';';
                $connect .= 'PWD=' . $DB['PASSWORD'] . ';';
                $DB['DB'] = @db2_connect($connect, $DB['USER'], $DB['PASSWORD']);
                if (!$DB['DB']) {
                    $error = 'Error connecting to database: ' . db2_conn_errormsg();
                    $result = false;
                } else {
                    $options = array('db2_attr_case' => DB2_CASE_LOWER);
                    db2_set_option($DB['DB'], $options, 1);
                    if (isset($DB['SCHEMA']) && $DB['SCHEMA'] != '') {
                        DBexecute('SET CURRENT SCHEMA=' . zbx_dbstr($DB['SCHEMA']));
                    }
                }
                if ($result) {
                    $dbBackend = new Db2DbBackend();
                }
                break;
            case ZBX_DB_SQLITE3:
                if (file_exists($DB['DATABASE'])) {
                    init_sqlite3_access();
                    lock_sqlite3_access();
                    try {
                        $DB['DB'] = @new SQLite3($DB['DATABASE'], SQLITE3_OPEN_READWRITE);
                    } catch (Exception $e) {
                        $error = 'Error connecting to database.';
                        $result = false;
                    }
                    unlock_sqlite3_access();
                } else {
                    $error = 'Missing database';
                    $result = false;
                }
                if ($result) {
                    $dbBackend = new SqliteDbBackend();
                }
                break;
            default:
                $error = 'Unsupported database';
                $result = false;
        }
    }
    if ($result && !$dbBackend->checkDbVersion()) {
        $error = $dbBackend->getError();
        $result = false;
    }
    if (false == $result) {
        $DB['DB'] = null;
    }
    return $result;
}
示例#19
0
文件: DoPgsql.php 项目: chaobj001/tt
 public function getAttribute($attribute)
 {
     switch ($attribute) {
         case DoLite::ATTR_SERVER_INFO:
             return pg_parameter_status($this->_connection, 'server_encoding');
             break;
         case DoLite::ATTR_SERVER_VERSION:
             return pg_parameter_status($this->_connection, 'server_version');
             break;
         case DoLite::ATTR_CLIENT_VERSION:
             return pg_parameter_status($this->_connection, 'server_version') . ' ' . pg_parameter_status($this->_connection, 'client_encoding');
             break;
         case DoLite::ATTR_PERSISTENT:
             return $this->_persistent;
             break;
     }
     return null;
 }
示例#20
0
<?php

// @Ravi.Bhure@symphonysv.com
include 'config/db.php';
// attempt a connection
$dbh = pg_connect("host={$hostname_DB} dbname=postgres user={$username_DB} password={$password_DB}");
if (!$dbh) {
    die("Error in connection: " . pg_last_error());
}
// get value of 'server_version' variable
echo "Server version: " . pg_parameter_status($dbh, 'server_version');
示例#21
0
文件: pgsql.php 项目: cbsistem/nexos
 public function connect()
 {
     $connect_string = '';
     if ($this->cfg['host']) {
         $connect_string .= ' host=' . $this->cfg['host'];
     }
     if ($this->cfg['hostaddr']) {
         $connect_string .= ' hostaddr=' . $this->cfg['hostaddr'];
     }
     if ($this->cfg['port']) {
         $connect_string .= ' port=' . $this->cfg['port'];
     }
     if ($this->cfg['username']) {
         $connect_string .= ' user='******'username'];
     }
     if ($this->cfg['password']) {
         $connect_string .= ' password='******'password'];
     }
     if ($this->cfg['database']) {
         $connect_string .= ' dbname=' . $this->cfg['database'];
     }
     if (!($this->connection = pg_connect($connect_string))) {
         throw new Poodle_SQL_Exception(pg_last_error(), 0, Poodle_SQL_Exception::NO_CONNECTION);
     }
     $this->server_info = pg_parameter_status($this->connection, 'server_version');
     $v = explode('.', $this->server_info);
     $this->server_version = $v[0] * 10000 + $v[1] * 100 + min(99, $v[2]);
     $v = pg_version($this->connection);
     $this->client_info = $v['client'];
     $v = explode('.', $v['client']);
     $this->client_version = $v[0] * 10000 + $v[1] * 100 + min(99, $v[2]);
     $this->v81 = version_compare($this->server_info, '8.1', '>=');
     $this->set_charset();
 }
示例#22
0
 /**
  *
  * @param integer $id the attribut id
  * @return string the attribute value
  * @see PDO::getAttribute()
  */
 public function getAttribute($id)
 {
     switch ($id) {
         case self::ATTR_CLIENT_VERSION:
             $v = pg_version($this->_connection);
             return array_key_exists($v['client']) ? $v['client'] : '';
         case self::ATTR_SERVER_VERSION:
             return pg_parameter_status($this->_connection, "server_version");
             break;
     }
     return "";
 }
示例#23
0
 /**
  * Returns list of tables.
  * @return array
  */
 public function getTables()
 {
     $version = pg_parameter_status($this->resource, 'server_version');
     if ($version < 7.4) {
         throw new DibiDriverException('Reflection requires PostgreSQL 7.4 and newer.');
     }
     $query = "\n\t\t\tSELECT\n\t\t\t\ttable_name AS name,\n\t\t\t\tCASE table_type\n\t\t\t\t\tWHEN 'VIEW' THEN 1\n\t\t\t\t\tELSE 0\n\t\t\t\tEND AS view\n\t\t\tFROM\n\t\t\t\tinformation_schema.tables\n\t\t\tWHERE\n\t\t\t\ttable_schema = current_schema()";
     if ($version >= 9.300000000000001) {
         $query .= "\n\t\t\t\tUNION ALL\n\t\t\t\tSELECT\n\t\t\t\t\tmatviewname, 1\n\t\t\t\tFROM\n\t\t\t\t\tpg_matviews\n\t\t\t\tWHERE\n\t\t\t\t\tschemaname = current_schema()";
     }
     $res = $this->query($query);
     $tables = pg_fetch_all($res->resultSet);
     return $tables ? $tables : array();
 }
示例#24
0
 /**
  * @return string Version information from the database
  */
 function getServerVersion()
 {
     if (!isset($this->numericVersion)) {
         $versionInfo = pg_version($this->mConn);
         if (version_compare($versionInfo['client'], '7.4.0', 'lt')) {
             // Old client, abort install
             $this->numericVersion = '7.3 or earlier';
         } elseif (isset($versionInfo['server'])) {
             // Normal client
             $this->numericVersion = $versionInfo['server'];
         } else {
             // Bug 16937: broken pgsql extension from PHP<5.3
             $this->numericVersion = pg_parameter_status($this->mConn, 'server_version');
         }
     }
     return $this->numericVersion;
 }
 /**
  * Returns the PostgreSQL version.
  * 
  * @return 	string
  */
 public function getVersion()
 {
     $version = pg_parameter_status($this->linkID, 'server_version');
     if (!empty($version)) {
         return $version;
     }
     return parent::getVersion();
 }