Example #1
0
 /**
  * Connect to database
  *
  * @param array $options
  * @return array
  */
 public function connect($options)
 {
     $result = ['version' => null, 'status' => 0, 'error' => [], 'errno' => 0, 'success' => false];
     // we could pass an array or connection string right a way
     if (is_array($options)) {
         $str = 'host=' . $options['host'] . ' port=' . $options['port'] . ' dbname=' . $options['dbname'] . ' user='******'username'] . ' password='******'password'];
     } else {
         $str = $options;
     }
     $connection = pg_connect($str);
     if ($connection !== false) {
         $this->db_resource = $connection;
         $this->connect_options = $options;
         $this->commit_status = 0;
         pg_set_error_verbosity($connection, PGSQL_ERRORS_VERBOSE);
         pg_set_client_encoding($connection, 'UNICODE');
         $result['version'] = pg_version($connection);
         $result['status'] = pg_connection_status($connection) === PGSQL_CONNECTION_OK ? 1 : 0;
         $result['success'] = true;
     } else {
         $result['error'][] = 'db::connect() : Could not connect to database server!';
         $result['errno'] = 1;
     }
     return $result;
 }
Example #2
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;
     }
 }
 public function lastInsertId()
 {
     $_temp = $this->lastHash;
     $lastResult = $this->results[$this->lastHash];
     $this->executeQuery("SELECT version() AS ver");
     $row = $this->getRow();
     $ver = pg_version($this->connection);
     $v = $ver['server'];
     $table = func_num_args() > 0 ? func_get_arg(0) : null;
     $column = func_num_args() > 1 ? func_get_arg(1) : null;
     if ($table == null && $v == '8.1') {
         $sql = "SELECT LASTVAL() AS ins_id";
     } elseif ($table != null && $column != null && $v >= '8.0') {
         $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column);
         $this->execte($sql);
         $row = $this->getRow();
         $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row['seq']);
     } elseif ($table != null) {
         // seq_name passed in table parameter
         $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table);
     } else {
         return pg_last_oid($lastResult);
     }
     $this->execute($sql);
     $row = $this->getRow();
     $this->lasthash = $_temp;
     return $row['ins_id'];
 }
Example #4
0
function navi()
{
    global $SIDU;
    $conn = $SIDU['conn'][$SIDU[0]];
    $link = @explode(',', $_GET['id']);
    $eng = @array('my' => 'MySQL', 'pg' => 'Postgres', 'sl' => 'SQLite');
    @sidu_sort($SIDU[5], $SIDU[6], $SIDU[7], $SIDU['page']['sortObj']);
    $obj = @array("r" => @lang(1416), "v" => @lang(1417), "S" => @lang(1418), "f" => @lang(1419));
    if ($link[3] != '') {
        if ($link[3] == 'r') {
            echo "<a href='tab-new.php?id={$SIDU['0']},{$SIDU['1']},{$SIDU['2']},{$SIDU['3']},{$SIDU['4']},{$SIDU['5']},{$SIDU['6']}' onclick=\"xwin(this.href,700,500);return false\" ", @html_hkey("=", @lang(1401)), ">", @html_img('img/tool-add'), "</a>{$SIDU['sep']}";
        }
        if ($link[3] == 'r' || $link[3] == 'v') {
            echo "<a href='#' ", @html_hkey("E", @lang(1402)), " onclick='dbexp(\"{$SIDU['0']},{$SIDU['1']},{$SIDU['2']},{$SIDU['3']}\",\"objs[]\")'>", @html_img('img/tool-down'), $SIDU['page']['menuText'] ? @lang(1403) : "", "</a>";
        }
        if ($link[3] == 'r') {
            echo " <a href='imp.php?id={$SIDU['0']},{$SIDU['1']},{$SIDU['2']}' ", @html_hkey("I", @lang(1404)), " onclick='xwin(this.href);return false'>", @html_img('img/tool-imp'), $SIDU['page']['menuText'] ? @lang(1405) : "", "</a>";
        }
        if ($link[3] == 'r') {
            echo " <a href='#' onclick=\"showHide('objTool')\" title='", @lang(1406), "'>", @html_img('img/tool-sys'), $SIDU['page']['menuText'] ? @lang(1407) : "", "</a>\n\t\t\t<a href='#' onclick=\"setv('objcmd','Empty');return (confirm('", @lang(1409), "') ? dataTab.submit() : false)\" ", @html_hkey("-", @lang(1410)), ">", @html_img('img/tool-flush'), $SIDU['page']['menuText'] ? @lang(1408) : "", "</a>";
        }
        echo " <a href='#' onclick=\"setv('objcmd','Drop'); return (confirm('", @lang(1412, $obj[$SIDU[3]]), "') ? dataTab.submit() : false)\" ", @html_hkey("X", @lang(1413)), ">", @html_img('img/tool-x'), $SIDU['page']['menuText'] ? @lang(1411) : "", "</a>\n\t\t\t<a href='" . ($conn[1] == "sl" ? "tab.php?id={$SIDU['0']},{$SIDU['1']},0,r,sqlite_master'" : "#' onclick=\"showHide('DBseek')\"") . " ", @html_hkey("F", @lang(1414)), ">", @html_img('img/tool-find'), $SIDU['page']['menuText'] ? @lang(1415) : "", "</a>{$SIDU['sep']}", @html_img("img/x{$link['3']}"), " <a href='db.php?id={$link['0']},{$link['1']},,,,{$SIDU['5']},{$SIDU['6']}'>{$link['1']}</a>", $link[2] ? " ยป <a href='db.php?id={$link['0']},{$link['1']},{$link['2']},{$link['3']},,{$SIDU['5']},{$SIDU['6']}'>{$link['2']}</a>" : "", $link[4] != '' ? " ยป {$link['4']}" : "";
    } else {
        if ($conn[1] == "my") {
            $serv['server'] = @mysql_get_server_info();
        } elseif ($conn[1] == "pg") {
            $serv = @pg_version();
        } else {
            $serv['server'] = @sqlite_libversion();
        }
        echo @html_img("img/eng-{$conn['1']}"), " <b>SIDU 3.0</b> for <b>{$eng[$conn[1]]}</b>\n\t\t{$SIDU['sep']}<a href='" . ($conn[1] == "sl" ? "tab.php?id={$SIDU['0']},{$SIDU['1']},0,r,sqlite_master'" : "#' onclick=\"showHide('DBseek')\"") . " ", @html_hkey("F", @lang(1414)), @html_img('img/tool-find'), "</a>\n\t\t<a href='db.php?id={$link['0']},,,,,{$SIDU['5']},{$SIDU['6']}'><b>", $conn[1] == "sl" ? "SQLite" : "{$conn['3']}@{$conn['2']}", "</b></a> v {$serv['server']}\n\t\t{$SIDU['sep']} ", @date("Y-m-d H:i:s");
    }
}
Example #5
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;
 }
Example #6
0
 /**
  * Gets the name of the correct database driver to use.  As a side effect,
  * sets the platform.
  * @param (return-by-ref) $description A description of the database and version
  * @return The class name of the driver eg. Postgres84
  * @return null if version is < 7.4
  * @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'];
         }
     }
     // If we didn't manage to get the version without a query, query...
     if (!isset($version)) {
         $adodb = new ADODB_base($this->conn);
         $sql = "SELECT VERSION() AS version";
         $field = $adodb->selectField($sql, 'version');
         // Check the platform, if it's mingw, set it
         if (preg_match('/ mingw /i', $field)) {
             $this->platform = 'MINGW';
         }
         $params = explode(' ', $field);
         if (!isset($params[1])) {
             return -3;
         }
         $version = $params[1];
         // eg. 8.4.4
     }
     $description = "PostgreSQL {$version}";
     // Detect version and choose appropriate database driver
     switch (substr($version, 0, 3)) {
         case '8.4':
             return 'Postgres';
             break;
         case '8.3':
             return 'Postgres83';
             break;
         case '8.2':
             return 'Postgres82';
             break;
         case '8.1':
             return 'Postgres81';
             break;
         case '8.0':
         case '7.5':
             return 'Postgres80';
             break;
         case '7.4':
             return 'Postgres74';
             break;
     }
     /* All <7.4 versions are not supported */
     // if major version is 7 or less and wasn't catch in the
     // switch/case block, we have an unsupported version.
     if ((int) substr($version, 0, 1) < 8) {
         return null;
     }
     // If unknown version, then default to latest driver
     return 'Postgres';
 }
Example #7
0
 public static function pgVersion()
 {
     // pg_version is only defined in postgres 7.4 and later
     if (function_exists('pg_version')) {
         return pg_version(self::connection());
     } else {
         // 7.4 is pretty old so older versions probably
         // won't support what we're looking for
         return 0;
     }
 }
Example #8
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;
 }
Example #9
0
 public static function version($mode = 'server')
 {
     if (array_key_exists('version', self::$dbProperties)) {
         return self::$dbProperties['version'];
     } else {
         self::$dbProperties['version'] = pg_version();
         if ($mode == 'server') {
             return self::$dbProperties['version']['server'];
         } else {
             return self::$dbProperties['version']['client'];
         }
     }
 }
 public function getDatabaseVersion($databaseConfig)
 {
     $conn = $this->createConnection($databaseConfig, $error);
     if (!$conn) {
         return false;
     } elseif ($conn instanceof PDO) {
         return $conn->getAttribute(PDO::ATTR_SERVER_VERSION);
     } elseif (is_resource($conn)) {
         $info = pg_version($conn);
         return $info['server'];
     } else {
         return false;
     }
 }
Example #11
0
 /**
  * Database Engine detection
  * @return string the database versin
  */
 public static function dbVersion()
 {
     $profile = jDb::getProfile();
     //@TODO get the current dbLink to give it to each RDBMS function
     /*
             $tools = jDb::getTools();
             $version = $tools->dbVersion();*/
     if ($profile['driver'] == 'pgsql') {
         $version = pg_version();
     } elseif ($profile['driver'] == 'mysql') {
         $version = mysql_get_server_info();
     } elseif ($profile['driver'] == 'sqlite') {
         $version = sqlite_version();
     }
     return $profile['driver'] . ' ' . $version;
 }
Example #12
0
 /**
  * ่ฟžๆŽฅๆ•ฐๆฎๅบ“
  * @param array $array ๆ•ฐๆฎๅบ“่ฟžๆŽฅ้…็ฝฎ
  *              $array=array(
  *                  'pgsql_server',
  *                  'pgsql_username',
  *                  'pgsql_password',
  *                  'pgsql_name',
  *                  'pgsql_pre',
  *                  'pgsql_port',
  *                  'persistent')
  *                  )
  * @return bool
  */
 public function Open($array)
 {
     $s = "host={$array[0]} port={$array[5]} dbname={$array[3]} user={$array[1]} password={$array[2]} options='--client_encoding=UTF8'";
     if (false == $array[5]) {
         $db_link = pg_connect($s);
     } else {
         $db_link = pg_pconnect($s);
     }
     if (!$db_link) {
         return false;
     } else {
         $this->dbpre = $array[4];
         $this->db = $db_link;
         $v = pg_version($db_link);
         $this->version = $v['client'];
         return true;
     }
 }
Example #13
0
 /**
  * Db_Pgsql constructor.
  *
  * @param  array $args
  * @throws \Exception
  */
 public function __construct(array $args)
 {
     $this->args = $args;
     if (!is_callable('pgsql_connect')) {
         throw new \Exception(__METHOD__ . ': pgsql_connect is not supported.');
     }
     $this->conn = pg_connect(sprintf('host=%s user=%s password=%s dbname=%s', $args['host'], $args['user'], $args['pass'], $args['name']));
     if ($this->conn === false) {
         throw new \Exception(__METHOD__ . ': failed to connect to PostgreSQL server.');
     }
     $version = pg_version($this->conn);
     if (is_array($version) && isset($version['server'])) {
         $this->serverVersion = $this->getIntVersion($version['server']);
     } else {
         $this->serverVersion = 0;
     }
     if (!empty($args['charset'])) {
         pg_set_client_encoding($this->conn, $args['charset']);
     }
 }
Example #14
0
 public function connect($dbIP, $dbUser, $dbPass, $dbName, $dbPort = null)
 {
     // check parameters
     if ($dbIP == '') {
         die('<b>ERROR:</b> no database host provided... <b>w2db.php, line ' . __LINE__ . '</b>');
     }
     if ($dbName == '') {
         die('<b>ERROR:</b> no database name provided... <b>w2db.php, line ' . __LINE__ . '</b>');
     }
     if ($dbUser == '') {
         die('<b>ERROR:</b> no database user provided... <b>w2db.php, line ' . __LINE__ . '</b>');
     }
     //if ($dbPass == '') die('no database password provided');
     $this->dbName = $dbName;
     // connect
     if ($this->dbType == 'postgres') {
         $this->dbConn = pg_connect("host={$dbIP} " . ($dbPort != null ? "port={$dbPort} " : "") . "dbname={$dbName} user={$dbUser} password={$dbPass}");
         if (!$this->dbConn) {
             $this->dbConn = null;
             print "<b>ERROR:</b> Cannot connect to postgres.<br>";
             return false;
         }
         $this->dbVersion = pg_version($this->dbConn);
         $this->dbVersion['host'] = pg_host($this->dbConn);
     }
     if ($this->dbType == 'mysql') {
         $this->dbConn = mysql_connect($dbIP . ($dbPort != null ? ":" . $dbPort : ""), $dbUser, $dbPass);
         if (!$this->dbConn) {
             $this->dbConn = null;
             print "<b>ERROR:</b> Cannot connect to mysql.<br>";
             return false;
         }
         mysql_select_db($dbName);
         $this->dbVersion = array();
         $this->dbVersion['client'] = mysql_get_client_info();
         $this->dbVersion['protocol'] = mysql_get_proto_info($this->dbConn);
         $this->dbVersion['server'] = mysql_get_server_info($this->dbConn);
         $this->dbVersion['host'] = mysql_get_host_info($this->dbConn);
     }
 }
Example #15
0
 /**
 +----------------------------------------------------------
 * ่ฟžๆŽฅๆ•ฐๆฎๅบ“ๆ–นๆณ•
 +----------------------------------------------------------
 * @access public
 +----------------------------------------------------------
 * @throws ThinkExecption
 +----------------------------------------------------------
 */
 public function connect($config = '', $linkNum = 0)
 {
     if (!isset($this->linkID[$linkNum])) {
         if (empty($config)) {
             $config = $this->config;
         }
         $conn = $this->pconnect ? 'pg_pconnect' : 'pg_connect';
         $this->linkID[$linkNum] = $conn('host=' . $config['hostname'] . ' port=' . $config['hostport'] . ' dbname=' . $config['database'] . ' user='******'username'] . ' password='******'password']);
         if (pg_connection_status($this->linkID[$linkNum]) !== 0) {
             throw_exception($this->error(false));
         }
         $pgInfo = pg_version($this->linkID[$linkNum]);
         $this->dbVersion = $pgInfo['server'];
         // ๆ ‡่ฎฐ่ฟžๆŽฅๆˆๅŠŸ
         $this->connected = true;
         //ๆณจ้”€ๆ•ฐๆฎๅบ“ๅฎ‰ๅ…จไฟกๆฏ
         if (1 != C('DB_DEPLOY_TYPE')) {
             unset($this->config);
         }
     }
     return $this->linkID[$linkNum];
 }
Example #16
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;
 }
 public function getDatabaseVersion($databaseConfig)
 {
     $version = 0;
     $username = $databaseConfig['username'] ? $databaseConfig['username'] : '';
     $password = $databaseConfig['password'] ? $databaseConfig['password'] : '';
     $server = $databaseConfig['server'];
     $userPart = $username ? " user={$username}" : '';
     $passwordPart = $password ? " password={$password}" : '';
     $connstring = "host={$server} port=5432 dbname=postgres {$userPart}{$passwordPart}";
     $conn = @pg_connect($connstring);
     $info = @pg_version($conn);
     $version = $info && isset($info['server']) ? $info['server'] : null;
     if (!$version) {
         // fallback to using the version() function
         $result = @pg_query($conn, "SELECT version()");
         $row = @pg_fetch_array($result);
         if ($row && isset($row[0])) {
             $parts = explode(' ', trim($row[0]));
             // ASSUMPTION version number is the second part e.g. "PostgreSQL 8.4.3"
             $version = trim($parts[1]);
         }
     }
     return $version;
 }
Example #18
0
 /**
  * Insert ID
  *
  * @return	string
  */
 public function insert_id()
 {
     $v = pg_version($this->conn_id);
     $v = isset($v['server']) ? $v['server'] : 0;
     // 'server' key is only available since PosgreSQL 7.4
     $table = func_num_args() > 0 ? func_get_arg(0) : NULL;
     $column = func_num_args() > 1 ? func_get_arg(1) : NULL;
     if ($table === NULL && $v >= '8.1') {
         $sql = 'SELECT LASTVAL() AS ins_id';
     } elseif ($table !== NULL) {
         if ($column !== NULL && $v >= '8.0') {
             $sql = 'SELECT pg_get_serial_sequence(\'' . $table . "', '" . $column . "') AS seq";
             $query = $this->query($sql);
             $query = $query->row();
             $seq = $query->seq;
         } else {
             // seq_name passed in table parameter
             $seq = $table;
         }
         $sql = 'SELECT CURRVAL(\'' . $seq . "') AS ins_id";
     } else {
         return pg_last_oid($this->result_id);
     }
     $query = $this->query($sql);
     $query = $query->row();
     return (int) $query->ins_id;
 }
 /**
  * checks the environment
  *
  * @return array with success/failure values for the given attributes
  * 
  */
 private function _check()
 {
     foreach ($this->values as $key => $value) {
         if ($value['tag'] == 'ENVIROMENT') {
             switch ($value['attributes']['NAME']) {
                 case 'Zend':
                     $required = $value['attributes']['VERSION'];
                     $zend = Zend_Version::VERSION;
                     $operator = $value['attributes']['OPERATOR'] == 'biggerThan' ? '>' : '<';
                     $text = $value['attributes']['NAME'] . ' ' . $operator . ' ' . $required;
                     if (version_compare($zend, $required, $operator)) {
                         $data[] = array($text, 'SUCCESS');
                     } else {
                         $data[] = array($text . ' (version is ' . $zend . ')', 'FAILURE');
                     }
                     break;
                 case 'PHP':
                     if (version_compare($value['attributes']['VERSION'], phpversion(), '<=')) {
                         $data[] = array($value['attributes']['NAME'], 'SUCCESS');
                     } else {
                         Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' PHP version incompatible: ' . phpversion() . ' < ' . $value['attributes']['VERSION']);
                         $data[] = array($value['attributes']['NAME'], 'FAILURE');
                     }
                     break;
                 case 'MySQL':
                     // get setup controller for database connection
                     if (Setup_Core::configFileExists()) {
                         $dbConfig = Tinebase_Core::getConfig()->database;
                         $hostnameWithPort = isset($dbConfig->port) ? $dbConfig->host . ':' . $dbConfig->port : $dbConfig->host;
                         $link = @mysql_connect($hostnameWithPort, $dbConfig->username, $dbConfig->password);
                         if (!$link) {
                             //die('Could not connect to mysql database: ' . mysql_error());
                             Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . 'Could not connect to mysql database: ' . mysql_error());
                             Setup_Core::set(Setup_Core::CHECKDB, FALSE);
                         }
                         $mysqlVersion = @mysql_get_server_info();
                     } else {
                         $mysqlVersion = @mysql_get_client_info();
                     }
                     // some version strings have more than just the version
                     preg_match('/\\d+\\.\\d+\\.\\d+/', $mysqlVersion, $matches);
                     $mysqlVersion = is_array($matches) ? $matches[0] : $mysqlVersion;
                     $text = $value['attributes']['NAME'];
                     if (version_compare($value['attributes']['VERSION'], $mysqlVersion, '<=')) {
                         $data[] = array($text, 'SUCCESS');
                     } else {
                         Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' MySQL version incompatible: ' . $mysqlVersion . ' < ' . $value['attributes']['VERSION']);
                         $data[] = array($text, 'FAILURE');
                     }
                     break;
                 case 'PgSQL':
                     $pgsqlVersion = '0.0.0';
                     // get setup controller for database connection
                     if (Setup_Core::configFileExists()) {
                         $dbConfig = Tinebase_Core::getConfig()->database;
                         $hostname = $dbConfig->host;
                         $port = isset($dbConfig->port) ? $dbConfig->port : '5432';
                         $user = $dbConfig->username;
                         $password = $dbConfig->password;
                         $link = @pg_connect("host={$hostname} port={$port} user={$user} password={$password}");
                         if (PGSQL_CONNECTION_BAD === pg_connection_status($link)) {
                             //die('Could not connect to postgresql database: ' . pg_errormessage());
                             Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . 'Could not connect to postgresql database: ' . pg_errormessage());
                             Setup_Core::set(Setup_Core::CHECKDB, FALSE);
                         } else {
                             $pgsqlVersion = @pg_version($link);
                             $pgsqlVersion = $pgsqlVersion['server'];
                         }
                     }
                     $text = $value['attributes']['NAME'];
                     if (version_compare($value['attributes']['VERSION'], $pgsqlVersion, '<=')) {
                         $data[] = array($text, 'SUCCESS');
                     } else {
                         Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' PostgreSQL version incompatible: ' . $pgsqlVersion . ' < ' . $value['attributes']['VERSION']);
                         $data[] = array($text, 'FAILURE');
                     }
                     break;
                 default:
                     $data[] = array($value['attributes']['NAME'], 'FAILURE');
                     break;
             }
         } else {
             if ($value['tag'] == 'EXTENSION') {
                 //print_r($this->loadedExtensions);
                 foreach ($value as $extensionArray) {
                     if (is_array($extensionArray)) {
                         $succeeded = false;
                         if (in_array($extensionArray['NAME'], $this->loadedExtensions)) {
                             $passed[] = true;
                             if ($this->values[$key + 1]['tag'] == 'INISET') {
                                 $iniSettings = ini_get_all($extensionArray['NAME']);
                                 //print_r($iniSettings);
                                 $i = 1;
                                 while ($values[$key + $i]['tag'] == 'INISET') {
                                     switch ($values[$key + $i]['attributes']['OPERATOR']) {
                                         case '<=':
                                             if (!$iniSettings[$values[$key + $i]['attributes']['NAME']][$values[$key + $i]['attributes']['SCOPE']] <= $values[$key + $i]['attributes']['VALUE']) {
                                                 $passed[] = false;
                                             }
                                             break;
                                         case '==':
                                             if (!$iniSettings[$values[$key + $i]['attributes']['NAME']][$values[$key + $i]['attributes']['SCOPE']] == $values[$key + $i]['attributes']['VALUE']) {
                                                 $passed[] = false;
                                             }
                                             break;
                                         case '>=':
                                             if (!$iniSettings[$values[$key + $i]['attributes']['NAME']][$values[$key + $i]['attributes']['SCOPE']] >= $values[$key + $i]['attributes']['VALUE']) {
                                                 $passed[] = false;
                                             }
                                             break;
                                         default:
                                             break;
                                     }
                                     $i++;
                                 }
                             }
                             // end INISET
                             if (!in_array(false, $passed)) {
                                 $succeeded = true;
                             }
                             unset($passed);
                             unset($iniSettings);
                         }
                         if ($succeeded) {
                             $data[] = array($extensionArray['NAME'], 'SUCCESS');
                         } else {
                             $data[] = array($extensionArray['NAME'], 'FAILURE');
                         }
                     }
                 }
             }
         }
         // end EXTENSION
     }
     // end foreach
     return $data;
 }
Example #20
0
    }
    print_row("PEAR::MDB2#mysql", $result, $status);
}
//Database Version
if (isset($maia_sql_dsn)) {
    if (preg_match('/^mysqli/', $maia_sql_dsn)) {
        $db_version = mysqli_get_server_info($test_dbh->connection);
        $status = OK;
        $result = "No minimum specified yet... Installed: " . $db_version;
    } elseif (preg_match('/^mysql/', $maia_sql_dsn)) {
        $db_version = mysql_get_server_info($test_dbh->connection);
        $status = OK;
        $result = "No minimum specified yet... Installed: " . $db_version;
    } elseif (preg_match('/^pgsql/', $maia_sql_dsn)) {
        if (function_exists("pg_version")) {
            $pg_version_result = pg_version($test_dbh->connection);
            $db_version = $pg_version_result['server'];
            if ($db_version >= "8.0") {
                $status = OK;
                $result = "Database version: " . $db_version;
            } else {
                $status = ERROR;
                $result = "Postgresql >= 8.0 required.";
            }
        } else {
            $status = WARN;
            $result = "Cannot determine database version.  We recommend Postgresql > 8.0; Please verify this before continuing.";
        }
    } else {
        $status = ERROR;
        $result = "Unsupported database";
Example #21
0
                        <tr>
                            <td>MySQL Version</td>
                            <td><?php 
echo $mysql_running ? $mysql_version : 'N/A';
?>
</td>
                        </tr>


                        <?php 
$psql_is_connected = FALSE;
$psql_conn = pg_connect('host=localhost port=5432 dbname=scotchbox user=root password=root');
if ($psql_conn) {
    $psql_is_connected = TRUE;
}
$psql_version = pg_version($psql_conn)['client'];
pg_close($psql_conn);
?>
                        <tr>
                            <td>PostgreSQL is installed</td>
                            <td><i class="fa fa-<?php 
echo $psql_is_connected ? 'check' : 'times';
?>
"></i></td>
                        </tr>
                        <tr>
                            <td>PostgreSQL is connected</td>
                            <td><i class="fa fa-<?php 
echo $psql_is_connected ? 'check' : 'times';
?>
"></i></td>
Example #22
0
 /**
  * Return client version.
  *
  * @return string - the version
  */
 public function db_client_version()
 {
     $version = pg_version();
     return $version['client'];
 }
Example #23
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 "";
 }
Example #24
0
 /**
  * Return the database version.
  *
  * @return string
  */
 public function version()
 {
     $ver = pg_version($this->connection);
     return 'PostgreSQL ' . $ver['server'];
 }
Example #25
0
 /**
  * Get the version of the database connector.
  *
  * @return  string  The database connector version.
  *
  * @since   12.1
  */
 public function getVersion()
 {
     $this->connect();
     $version = pg_version($this->connection);
     return $version['server'];
 }
Example #26
0
 public function Output()
 {
     global $PG_CONN;
     $this->pgVersion = pg_version($PG_CONN);
     $V = "";
     $V .= "<table border=0 width='100%'><tr>\n";
     $V .= "<td valign='top'>\n";
     $text = _("Database Contents");
     $V .= "<h2>{$text}</h2>\n";
     $V .= $this->DatabaseContents();
     $V .= "</td>";
     $V .= "<td valign='top'>\n";
     $text = _("Database Metrics");
     $V .= "<h2>{$text}</h2>\n";
     $V .= $this->DatabaseMetrics();
     $V .= "</td>";
     $V .= "</tr></table>\n";
     $text = _("Active FOSSology queries");
     $V .= "<h2>{$text}</h2>\n";
     $V .= $this->DatabaseQueries();
     $text = _("Disk Space");
     $V .= "<h2>{$text}</h2>\n";
     $V .= $this->DiskFree();
     return $V;
 }
Example #27
0
 /**
  * Returns the server version string.
  *
  * @return string
  */
 public function server_version()
 {
     $pg_version = pg_version($this->conn);
     if (isset($pg_version['server_version'])) {
         return $pg_version['server_version'];
     } else {
         return 'n/a';
     }
 }
Example #28
0
 /**
  * Insert ID
  *
  * @access	public
  * @return	integer
  */
 function insert_id()
 {
     $v = $this->_version();
     $v = pg_version($this->conn_id);
     $v = isset($v['server']) ? $v['server'] : 0;
     $table = func_num_args() > 0 ? func_get_arg(0) : NULL;
     $column = func_num_args() > 1 ? func_get_arg(1) : NULL;
     if ($table == NULL && $v >= '8.1') {
         $sql = 'SELECT LASTVAL() as ins_id';
     } elseif ($table != NULL && $column != NULL && $v >= '8.0') {
         $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column);
         $query = $this->query($sql);
         $row = $query->row();
         $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq);
     } elseif ($table != NULL) {
         // seq_name passed in table parameter
         $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table);
     } else {
         return pg_last_oid($this->result_id);
     }
     $query = $this->query($sql);
     $row = $query->row();
     return $row->ins_id;
 }
Example #29
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 database server info array
  * @return array Array containing 'description' and 'version' info
  */
 public function get_server_info()
 {
     static $info;
     if (!$info) {
         $this->query_start("--pg_version()", null, SQL_QUERY_AUX);
         $info = pg_version($this->pgsql);
         $this->query_end(true);
     }
     return array('description' => $info['server'], 'version' => $info['server']);
 }