• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP pg_connection_status函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中pg_connection_status函数的典型用法代码示例。如果您正苦于以下问题:PHP pg_connection_status函数的具体用法?PHP pg_connection_status怎么用?PHP pg_connection_status使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了pg_connection_status函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: _connect

 protected function _connect()
 {
     $connstr = '';
     foreach ($this->_config as $param => $value) {
         if ($value) {
             switch ($param) {
                 case 'host':
                     $connstr .= "host={$value} ";
                     break;
                 case 'database':
                     $connstr .= "dbname={$value} ";
                     break;
                 case 'port':
                     $connstr .= "port={$value} ";
                     break;
                 case 'username':
                     $connstr .= "user={$value} ";
                     break;
                 case 'password':
                     $connstr .= "password={$value} ";
                     break;
             }
         }
     }
     if (isset($this->_config['persistent'])) {
         $this->_connection = pg_pconnect($connstr);
     } else {
         $this->_connection = pg_connect($connstr);
     }
     if (pg_connection_status($this->_connection) !== PGSQL_CONNECTION_OK) {
         $this->_errorHandler(1, "Cconnection failed. ");
     }
 }
开发者ID:TheProjecter,项目名称:skeleton,代码行数:33,代码来源:Postgres.php


示例2: connect

 public function connect()
 {
     if ($this->bConnected) {
         return $this->rConnection;
     }
     $iLevel = error_reporting();
     // to suppress E_WARNING that can happen
     error_reporting(0);
     if ($this->iPersistence == 0) {
         // plain connect
         $this->rConnection = pg_connect($this->sConnString, PGSQL_CONNECT_FORCE_NEW);
     } else {
         if ($this->iPersistence == 1) {
             // persistent connect
             $this->rConnection = pg_pconnect($this->sConnString);
         } else {
             if ($this->iPersistence == PGSQL_CONNECT_FORCE_NEW) {
                 // persistent connect forced new
                 $this->rConnection = pg_connect($this->sConnString, PGSQL_CONNECT_FORCE_NEW);
             }
         }
     }
     // lets restore previous level
     error_reporting($iLevel);
     $iConnStatus = pg_connection_status($this->rConnection);
     if ($iConnStatus !== PGSQL_CONNECTION_OK) {
         if (is_resource($this->rConnection)) {
             pg_close($this->rConnection);
         }
         throw new \Exception('Unable to connect.');
     }
     $this->bConnected = true;
     return $this->rConnection;
 }
开发者ID:denismilovanov,项目名称:libpostgres,代码行数:34,代码来源:LibPostgresDriver.php


示例3: castLink

 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;
 }
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:26,代码来源:PgSqlCaster.php


示例4: connect

 /**
  * 连接数据库方法
  * @access public
  */
 public function connect($config = '', $linkNum = 0)
 {
     if (!isset($this->linkID[$linkNum])) {
         if (empty($config)) {
             $config = $this->config;
         }
         $pconnect = !empty($config['params']['persist']) ? $config['params']['persist'] : $this->pconnect;
         $conn = $pconnect ? 'pg_pconnect' : 'pg_connect';
         $this->linkID[$linkNum] = $conn('host=' . $config['hostname'] . ' port=' . $config['hostport'] . ' dbname=' . $config['database'] . ' user=' . $config['username'] . '  password=' . $config['password']);
         if (0 !== pg_connection_status($this->linkID[$linkNum])) {
             E($this->error(false));
         }
         //设置编码
         pg_set_client_encoding($this->linkID[$linkNum], $config['charset']);
         //$pgInfo = pg_version($this->linkID[$linkNum]);
         //$dbVersion = $pgInfo['server'];
         // 标记连接成功
         $this->connected = true;
         //注销数据库安全信息
         if (1 != C('DB_DEPLOY_TYPE')) {
             unset($this->config);
         }
     }
     return $this->linkID[$linkNum];
 }
开发者ID:2flying2,项目名称:IDF-CTF-PLAT,代码行数:29,代码来源:Pgsql.class.php


示例5: getAttribute

 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;
     }
 }
开发者ID:PHPcomaptibility,项目名称:PHPPDO,代码行数:28,代码来源:pgsql.php


示例6: __construct

 function __construct($db_host, $db_user, $db_password, $db_name, $backend = "mysql")
 {
     define("DeveloperMailAddress", "[email protected]");
     define("RegDataMySql", "([1-2][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9])");
     define("RegDataIt", "([0-3][0-9]/[0-1][0-9]/[1-2][0-9][0-9][0-9])");
     define("RegTime", "([0-2][0-9]:[0-6][0-9]:[0-6][0-9])");
     define("RegDataTime", "([1-2][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-6][0-9]:[0-6][0-9])");
     $this->ReportHeader = "";
     $this->ReportFields = "";
     $this->BackEnd = $backend;
     $this->ResultStatus = "";
     $this->LastID = "";
     $this->SaveErrors = "";
     switch ($backend) {
         case "mysql":
             if (!($this->db = mysqli_connect($db_host, $db_user, $db_password))) {
                 $this->StampaErr("mysql_connect", "Errore durante la connessione al database," . " verificare i parametri.");
                 exit;
             }
             if (!mysqli_select_db($this->db, $db_name)) {
                 $this->StampaErr("mysql_select_db", "Errore durante la selezione del database," . " verificare i parametri.");
                 exit;
             }
             break;
         case "postgresql":
             if (!($this->db = pg_connect("host={$db_host} port=5432 dbname={$db_name} user={$db_user} password={$db_password}"))) {
                 echo "[Debug]: pg_connection_status: " . pg_connection_status($this->db) . " <br />";
                 $this->StampaErr("pg_connect", "Errore durante la connessione\n                            o selezione del database, verificare i parametri.");
                 exit;
             }
             break;
     }
     return $this->db;
 }
开发者ID:clagiordano,项目名称:weblibs,代码行数:34,代码来源:DatabaseLegacy.php


示例7: connect

 /**
  * 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=' . $options['username'] . ' password=' . $options['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;
 }
开发者ID:volodymyr-volynets,项目名称:backend,代码行数:31,代码来源:base.php


示例8: connect

 public function connect($parameters, $selectDB = false)
 {
     $this->lastParameters = $parameters;
     // Note: Postgres always behaves as though $selectDB = true, ignoring
     // any value actually passed in. The controller passes in true for other
     // connectors such as PDOConnector.
     // Escape parameters
     $arguments = array($this->escapeParameter($parameters, 'server', 'host', 'localhost'), $this->escapeParameter($parameters, 'port', 'port', 5432), $this->escapeParameter($parameters, 'database', 'dbname', 'postgres'), $this->escapeParameter($parameters, 'username', 'user'), $this->escapeParameter($parameters, 'password', 'password'));
     // Close the old connection
     if ($this->dbConn) {
         pg_close($this->dbConn);
     }
     // Connect
     $this->dbConn = @pg_connect(implode(' ', $arguments));
     if ($this->dbConn === false) {
         // Extract error details from PHP error handling
         $error = error_get_last();
         if ($error && preg_match('/function\\.pg-connect\\<\\/a\\>\\]\\: (?<message>.*)/', $error['message'], $matches)) {
             $this->databaseError(html_entity_decode($matches['message']));
         } else {
             $this->databaseError("Couldn't connect to PostgreSQL database.");
         }
     } elseif (pg_connection_status($this->dbConn) != PGSQL_CONNECTION_OK) {
         throw new ErrorException($this->getLastError());
     }
     //By virtue of getting here, the connection is active:
     $this->databaseName = empty($parameters['database']) ? PostgreSQLDatabase::MASTER_DATABASE : $parameters['database'];
 }
开发者ID:helpfulrobot,项目名称:silverstripe-postgresql,代码行数:28,代码来源:PostgreSQLConnector.php


示例9: is_connected

 protected function is_connected()
 {
     if (!$this->db) {
         return false;
     }
     if (pg_connection_status($this->db) != PGSQL_CONNECTION_OK) {
         return false;
     }
 }
开发者ID:BackupTheBerlios,项目名称:igoan,代码行数:9,代码来源:Igoandb.class.php


示例10: sql_query

function sql_query($qry, &$conn = 0)
{
    global $db;
    // If no database connection is supplied use default
    if (!$conn) {
        $conn =& $db;
    }
    if (!$conn) {
        print "NO DATABASE\n";
        exit;
    }
    // check if connection was opened too long
    if (isset($conn['date']) && time() - $conn['date'] > 3600) {
        debug("connection {$conn['connection']} opened too long, closing", "sql");
        $conn['date'] = null;
        pg_close($conn['connection']);
        unset($conn['connection']);
    }
    // check for database connection
    sql_connect($conn);
    // Rewrite SQL query
    call_hooks("pg_sql_query", $qry, $conn);
    // Do we want debug information?
    if (isset($conn['debug']) && $conn['debug']) {
        debug("CONN {$conn['title']}: " . $qry, "sql");
    }
    // Query
    $res = pg_query($conn['connection'], $qry);
    // There was an error - call hooks to inform about error
    if ($res === false) {
        // if postgresql connection died ...
        if (pg_connection_status($conn['connection']) == PGSQL_CONNECTION_BAD) {
            debug("sql connection died", "sql");
            pg_close($conn['connection']);
            unset($conn['connection']);
            call_hooks("sql_connection_failed", $conn);
            // if connection is back, retry query
            if (isset($conn['connection']) && pg_connection_status($conn['connection']) == PGSQL_CONNECTION_OK) {
                $res = pg_query($conn['connection'], $qry);
                if ($res !== false) {
                    debug("sql retry successful", "sql");
                    return $res;
                }
            } else {
                print "sql connection died\n";
                exit;
            }
        }
        $error = pg_last_error();
        call_hooks("sql_error", $db, $qry, $error);
        // If we want debug information AND we have an error, tell about it
        if (isset($conn['debug']) && $conn['debug']) {
            debug("CONN {$conn['title']}: " . pg_last_error(), "sql");
        }
    }
    return $res;
}
开发者ID:plepe,项目名称:modulekit-lib,代码行数:57,代码来源:sql.php


示例11: db_connect

 function db_connect()
 {
     $uri = "host={$this->mDatabaseHost} port={$this->mDatabasePort} dbname={$this->mDatabaseName} user={$this->mDatabaseUsername} password={$this->mDatabasePassword}";
     $connection = pg_connect($uri);
     if (pg_connection_status($connection) == PGSQL_CONNECTION_OK) {
         return $connection;
     }
     die('数据库访问错误!');
 }
开发者ID:iwater,项目名称:kissphp,代码行数:9,代码来源:PostgreSqlCommand.php


示例12: status

 function status()
 {
     $status = pg_connection_status($this->dbConnection);
     if ($status === PGSQL_CONNECTION_OK) {
         return "Connection status ok";
     } else {
         return "Connection status bad";
     }
 }
开发者ID:atahualpasf,项目名称:hipodromo,代码行数:9,代码来源:respaldodb.php


示例13: ifConnected

 public function ifConnected()
 {
     $stat = pg_connection_status($this->link);
     if ($stat === 0) {
         return true;
     } else {
         return false;
     }
 }
开发者ID:BackupTheBerlios,项目名称:alien-svn,代码行数:9,代码来源:alien_pgsql.php


示例14: db_backend_connection

function db_backend_connection()
{
    $conf = get_config();
    // connect to database
    $db = pg_connect($conf['database']['connect']) or die('Unable to connect to db node server');
    if (pg_connection_status($db) !== PGSQL_CONNECTION_OK) {
        die('db: Bad connection status');
    }
    return $db;
}
开发者ID:T1T4N,项目名称:ncrypt,代码行数:10,代码来源:db-pgsql.inc.php


示例15: connect

 public function connect($connection)
 {
     if (empty($connection)) {
         throw new Exception("Could not connect to any database without reequired connection data");
     } else {
         $this->connection = pg_connect($connection);
         $this->conn_stat = pg_connection_status($this->connection);
         if ($this->conn_stat != PGSQL_CONNECTION_OK) {
             throw new Exception("Could not connect to database... :(");
         }
     }
 }
开发者ID:jankovacs,项目名称:php-legs,代码行数:12,代码来源:PostgreSQL.php


示例16: do_sql

function do_sql($query)
{
    // Connect to DB
    $dbconn = $_GLOBAL['dbconn'];
    if (pg_connection_status($dbconn) !== PGSQL_CONNECTION_OK) {
        $dbconn = pg_connect("host=localhost dbname=training_diary user=athlete password=athlete0") or die('Could not connect: ' . pg_last_error());
        $_GLOBAL['dbconn'] = $dbconn;
    }
    #echo "\n<div><br>DEBUG $query <br></div> \n";
    $result = pg_query($query) or die('Query failed: ' . pg_last_error());
    #pg_close($dbconn);
    return $result;
}
开发者ID:robincj,项目名称:tlog,代码行数:13,代码来源:sql_functions.php


示例17: is_connected

 protected function is_connected()
 {
     if (!$this->db) {
         return false;
     }
     if (IFPG and pg_connection_status($this->db) != PGSQL_CONNECTION_OK) {
         return false;
     }
     if (IFMY) {
         return mysql_ping($this->db);
     }
     return true;
 }
开发者ID:BackupTheBerlios,项目名称:igoan-svn,代码行数:13,代码来源:Igoandb.class.php


示例18: __construct

 function __construct($connection_string)
 {
     //echo "Opening Connection\n";
     $this->pg_connection = pg_connect($connection_string);
     if (!$this->pg_connection) {
         throw new DatabaseException('Connection Error');
     }
     if (PGSQL_CONNECTION_OK != pg_connection_status($this->pg_connection)) {
         throw new DatabaseException(pg_errormessage($this->pg_connection));
     }
     // Timezone
     // Serialisation
     // Log?
 }
开发者ID:sandyman,项目名称:postgres-dbal,代码行数:14,代码来源:DatabaseRawConnection.php


示例19: connect

 function connect()
 {
     if ($this->connection != 0) {
         return pg_connection_status($this->connection) == PGSQL_CONNECTION_OK;
     }
     $this->connection = pg_connect("host={$this->host} port=5432 dbname={$this->db} user={$this->user} password={$this->pass}");
     if ($this->connection == 0) {
         return 0;
     }
     $this->queries = 0;
     if ($this->connection != 0) {
         return pg_connection_status($this->connection) == PGSQL_CONNECTION_OK;
     }
     return 0;
 }
开发者ID:Return-To-The-Roots,项目名称:s2map-php,代码行数:15,代码来源:pgsql.php


示例20: connect

 /**
  * @coroutine
  *
  * @param string $connectionString
  * @param float|int $timeout
  *
  * @return \Generator
  *
  * @resolve \Icicle\Postgres\Connection
  *
  * @throws \Icicle\Postgres\Exception\FailureException
  */
 function connect(string $connectionString, float $timeout = 0) : \Generator
 {
     if (!($connection = @\pg_connect($connectionString, \PGSQL_CONNECT_ASYNC | \PGSQL_CONNECT_FORCE_NEW))) {
         throw new FailureException('Failed to create connection resource');
     }
     if (\pg_connection_status($connection) === \PGSQL_CONNECTION_BAD) {
         throw new FailureException(\pg_last_error($connection));
     }
     if (!($socket = \pg_socket($connection))) {
         throw new FailureException('Failed to access connection socket');
     }
     $delayed = new Delayed();
     $callback = function ($resource, bool $expired) use(&$poll, &$await, $connection, $delayed, $timeout) {
         try {
             if ($expired) {
                 throw new TimeoutException('Connection attempt timed out.');
             }
             switch (\pg_connect_poll($connection)) {
                 case \PGSQL_POLLING_READING:
                     return;
                     // Connection not ready, poll again.
                 // Connection not ready, poll again.
                 case \PGSQL_POLLING_WRITING:
                     $await->listen($timeout);
                     return;
                     // Still writing...
                 // Still writing...
                 case \PGSQL_POLLING_FAILED:
                     throw new FailureException('Could not connect to PostgreSQL server');
                 case \PGSQL_POLLING_OK:
                     $poll->free();
                     $await->free();
                     $delayed->resolve(new BasicConnection($connection, $resource));
                     return;
             }
         } catch (\Throwable $exception) {
             $poll->free();
             $await->free();
             \pg_close($connection);
             $delayed->reject($exception);
         }
     };
     $poll = Loop\poll($socket, $callback, true);
     $await = Loop\await($socket, $callback);
     $poll->listen($timeout);
     $await->listen($timeout);
     return (yield $delayed);
 }
开发者ID:icicleio,项目名称:postgres,代码行数:60,代码来源:functions.php



注:本文中的pg_connection_status函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP pg_end_copy函数代码示例发布时间:2022-05-15
下一篇:
PHP pg_connect函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap