本文整理汇总了PHP中pg_pconnect函数的典型用法代码示例。如果您正苦于以下问题:PHP pg_pconnect函数的具体用法?PHP pg_pconnect怎么用?PHP pg_pconnect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pg_pconnect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: conectar
function conectar($server = IP_SERVER, $user = USER_DB, $pass = PASSWORD_DB, $based = DB, $puerto = PORT, $tipo_conexion = "N")
{
try {
switch ($tipo_conexion) {
case "N":
// Conexion a B.D no persistente
$this->id_conexion = @pg_connect("host={$server} port={$puerto} dbname={$based} user={$user} password={$pass}");
break;
case "P":
// Conexion a B.D persistente
$this->id_conexion = @pg_pconnect("host={$server} port={$puerto} dbname={$based} user={$user} password={$pass}");
break;
default:
// Otros casos
$this->id_conexion = @pg_connect("host={$server} port={$puerto} dbname={$based} user={$user} password={$pass}");
break;
}
if ($this->id_conexion) {
//$this->id_conexion->set_charset(CODEC);
return $this->id_conexion;
} else {
throw new Exception("Error 01: " . ($this->id_conexion ? pg_error($this->id_conexion) : 'Servidor o B.D. no disponible'));
}
} catch (Exception $e) {
$this->error1 = $e->getMessage();
return null;
}
}
示例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;
}
示例3: _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. ");
}
}
示例4: connect
function connect()
{
$this->close();
$p = $this->params;
$connstr = "dbname={$p['name']}";
if ($p['user']) {
$connstr .= " user={$p['user']}";
}
if ($p['pass']) {
$connstr .= " password={$p['pass']}";
}
if ($p['host']) {
$connstr .= " host={$p['host']}";
}
if ($p['port']) {
$connstr .= " port={$p['port']}";
}
if ($p['persistent']) {
$this->conn = pg_pconnect($connstr);
} else {
$this->conn = pg_connect($connstr);
}
if (!$this->conn) {
$this->_catch("Unable to connect to the database: " . pg_last_error());
return false;
}
return true;
}
示例5: open
public function open()
{
if (!$this->handle) {
if (!$this->port) {
$this->port = 5432;
}
$str_conn = "host={$this->server} port={$this->port} dbname={$this->source} user={$this->user} password={$this->pass}";
if ($this->persistent) {
$this->handle = pg_pconnect($str_conn);
} else {
$this->handle = pg_connect($str_conn);
}
if (!$this->handle) {
$this->connection_error(pg_last_error());
$this->handle = false;
return false;
}
// Keep track of the number of connections we create
$this->increment_counters();
}
// Flag Connection as Open
$this->conn_open = true;
// Start Transaction?
if (!$this->auto_commit && !$this->trans_started) {
$this->start_trans();
}
return true;
}
示例6: connect
function connect()
{
global $php_errormsg;
$persistent = isset($this->config['persistent']) ? $this->config['persistent'] : null;
$connstr = '';
if ($host = $this->config['host']) {
$connstr = 'host=' . $host;
}
if ($port = $this->config['port']) {
$connstr .= ' port=' . $port;
}
if ($database = $this->config['database']) {
$connstr .= ' dbname=\'' . addslashes($database) . '\'';
}
if ($user = $this->config['user']) {
$connstr .= ' user=\'' . addslashes($user) . '\'';
}
if ($password = $this->config['password']) {
$connstr .= ' password=\'' . addslashes($password) . '\'';
}
if ($persistent) {
$conn = @pg_pconnect($connstr);
} else {
$conn = @pg_connect($connstr);
}
if (!is_resource($conn)) {
$this->_raiseError($php_errormsg);
}
if (isset($this->config['charset']) && ($charset = $this->config['charset'])) {
pg_set_client_encoding($conn, $charset);
}
$this->connectionId = $conn;
}
示例7: connect
public function connect($config = [])
{
$this->config = $config;
$dsn = 'host=' . $this->config['host'] . ' ';
if (!empty($this->config['port'])) {
$dsn .= 'port=' . $this->config['port'] . ' ';
}
if (!empty($this->config['database'])) {
$dsn .= 'dbname=' . $this->config['database'] . ' ';
}
if (!empty($this->config['user'])) {
$dsn .= 'user=' . $this->config['user'] . ' ';
}
if (!empty($this->config['password'])) {
$dsn .= 'password=' . $this->config['password'] . ' ';
}
if (!empty($this->config['dsn'])) {
$dsn = $this->config['dsn'];
}
$dsn = rtrim($dsn);
$this->connect = $this->config['pconnect'] === true ? @pg_pconnect($dsn) : @pg_connect($dsn);
if (empty($this->connect)) {
die(getErrorMessage('Database', 'connectError'));
}
if (!empty($this->config['charset'])) {
pg_set_client_encoding($this->connect, $this->config['charset']);
}
}
示例8: db_connect
/**
* db_connect() - Connect to the database
* Notice the global vars that must be set up
* Sets up a global $gfconn variable which is used
* in other functions in this library.
*/
function db_connect()
{
global $sys_dbhost, $sys_dbuser, $sys_dbpasswd, $gfconn, $sys_dbname, $sys_db_use_replication, $sys_dbport, $sys_dbreaddb, $sys_dbreadhost;
//
// Connect to primary database
//
if (function_exists("pg_pconnect")) {
$gfconn = pg_pconnect(pg_connectstring($sys_dbname, $sys_dbuser, $sys_dbpasswd, $sys_dbhost, $sys_dbport));
} else {
print "function pg_pconnect doesn't exist: no postgresql interface";
exit;
}
//
// If any replication is configured, connect
//
if ($sys_db_use_replication) {
$gfconn2 = pg_pconnect(pg_connectstring($sys_dbreaddb, $sys_dbuser, $sys_dbpasswd, $sys_dbreadhost, $sys_dbreadport));
} else {
$gfconn2 = $gfconn;
}
//
// Now map the physical database connections to the
// "virtual" list that is used to distribute load in db_query()
//
define('SYS_DB_PRIMARY', $gfconn);
define('SYS_DB_STATS', $gfconn2);
define('SYS_DB_TROVE', $gfconn2);
define('SYS_DB_SEARCH', $gfconn2);
// Register top-level "finally" handler to abort current
// transaction in case of error
register_shutdown_function("system_cleanup");
}
示例9: connect
public function connect()
{
// Already connected
if (is_resource($this->connection)) {
return;
}
extract($this->config['connection']);
$str = (isset($socket) and $socket) ? '' : (isset($host) ? "host='{$host}'" : '');
$str .= isset($port) ? " port='{$port}'" : '';
$str .= isset($user) ? " user='{$user}'" : '';
$str .= isset($pass) ? " password='{$pass}'" : '';
$str .= isset($database) ? " dbname='{$database}'" : '';
// Connect to the database
$this->connection = $this->config['persistent'] === TRUE ? pg_pconnect($str, PGSQL_CONNECT_FORCE_NEW) : pg_connect($str, PGSQL_CONNECT_FORCE_NEW);
// A descriptive E_WARNING should have been thrown upon error
// Test the return value as a last resort
if (!is_resource($this->connection)) {
throw new Database_Exception('Unable to connect to database');
}
if (isset($this->config['character_set'])) {
// Set the character set
$this->set_charset($this->config['character_set']);
}
if (empty($this->config['schema'])) {
// Assume the default schema without changing the search path
$this->config['schema'] = 'public';
} else {
$this->schema($this->config['schema']);
}
}
示例10: sql_connect
/**
* Connect to server
*/
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false)
{
$this->connect_string = '';
if ($sqluser) {
$this->connect_string .= "user={$sqluser} ";
}
if ($sqlpassword) {
$this->connect_string .= "password={$sqlpassword} ";
}
if ($sqlserver) {
if (strpos($sqlserver, ':') !== false) {
list($sqlserver, $sqlport) = explode(':', $sqlserver);
$this->connect_string .= "host={$sqlserver} port={$sqlport} ";
} else {
if ($sqlserver != "localhost") {
$this->connect_string .= "host={$sqlserver} ";
}
if ($port) {
$this->connect_string .= "port={$port} ";
}
}
}
if ($database) {
$this->dbname = $database;
$this->connect_string .= "dbname={$database}";
}
$this->persistency = $persistency;
$this->db_connect_id = $this->persistency ? @pg_pconnect($this->connect_string) : @pg_connect($this->connect_string);
return $this->db_connect_id ? $this->db_connect_id : $this->sql_error('');
}
示例11: conectar
public function conectar()
{
if (!parent::$enlace) {
parent::$enlace = pg_pconnect('host=' . FS_HOST . ' dbname=' . FS_DB_NAME . ' port=' . FS_DB_PORT . ' user=' . FS_USERDB . ' password=' . FS_PASSDB);
}
return parent::$enlace;
}
示例12: connect
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));
}
}
}
示例13: DBLayer
function DBLayer($db_host, $db_username, $db_password, $db_name, $db_prefix, $p_connect)
{
$this->prefix = $db_prefix;
if ($db_host) {
if (strpos($db_host, ':') !== false) {
list($db_host, $dbport) = explode(':', $db_host);
$connect_str[] = 'host=' . $db_host . ' port=' . $dbport;
} else {
$connect_str[] = 'host=' . $db_host;
}
}
if ($db_name) {
$connect_str[] = 'dbname=' . $db_name;
}
if ($db_username) {
$connect_str[] = 'user=' . $db_username;
}
if ($db_password) {
$connect_str[] = 'password=' . $db_password;
}
if ($p_connect) {
$this->link_id = @pg_pconnect(implode(' ', $connect_str));
} else {
$this->link_id = @pg_connect(implode(' ', $connect_str));
}
if (!$this->link_id) {
error('Unable to connect to PostgreSQL server.', __FILE__, __LINE__);
}
// Setup the client-server character set (UTF-8)
if (!defined('FORUM_NO_SET_NAMES')) {
$this->set_names('utf8');
}
return $this->link_id;
}
示例14: OA_Dal_Delivery_connect
/**
* The function to open a database connection, or return the resource if already open
*
* @param string $database The name of the database config to use
* (Must match the database section name in the conf file)
* @return resource|false The PgSQL database resource
* or false on failure
*/
function OA_Dal_Delivery_connect($database = 'database')
{
// If a connection already exists, then return that
if ($database == 'database' && isset($GLOBALS['_MAX']['ADMIN_DB_LINK']) && is_resource($GLOBALS['_MAX']['ADMIN_DB_LINK'])) {
return $GLOBALS['_MAX']['ADMIN_DB_LINK'];
} elseif ($database == 'rawDatabase' && isset($GLOBALS['_MAX']['RAW_DB_LINK']) && is_resource($GLOBALS['_MAX']['RAW_DB_LINK'])) {
return $GLOBALS['_MAX']['RAW_DB_LINK'];
}
// No connection exists, so create one
$conf = $GLOBALS['_MAX']['CONF'];
if (!empty($conf[$database])) {
$dbConf = $conf[$database];
} else {
$dbConf = $conf['database'];
}
$dbParams = array();
$dbParams[] = 'port=' . (isset($dbConf['port']) ? $dbConf['port'] : 5432);
$dbParams[] = !empty($dbConf['protocol']) && $dbConf['protocol'] == 'unix' ? '' : 'host=' . $dbConf['host'];
$dbParams[] = empty($dbConf['username']) ? '' : 'user=' . $dbConf['username'];
$dbParams[] = empty($dbConf['password']) ? '' : 'password=' . $dbConf['password'];
$dbParams[] = 'dbname=' . $dbConf['name'];
if ($dbConf['persistent']) {
$dbLink = @pg_pconnect(join(' ', $dbParams));
} else {
$dbLink = @pg_connect(join(' ', $dbParams));
}
if ($dbLink && !empty($conf['databasePgsql']['schema'])) {
@pg_query($dbLink, "SET search_path='{$conf['databasePgsql']['schema']}'");
}
if ($dbLink && !empty($conf['databaseCharset']['checkComplete']) && !empty($conf['databaseCharset']['clientCharset'])) {
@pg_client_encoding($dbLink, $conf['databaseCharset']['clientCharset']);
}
return $dbLink;
}
示例15: sql_db
function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
{
$this->connect_string = "";
if ($sqluser) {
$this->connect_string .= "user={$sqluser} ";
}
if ($sqlpassword) {
$this->connect_string .= "password={$sqlpassword} ";
}
if ($sqlserver) {
if (ereg(":", $sqlserver)) {
list($sqlserver, $sqlport) = split(":", $sqlserver);
$this->connect_string .= "host={$sqlserver} port={$sqlport} ";
} else {
if ($sqlserver != "localhost") {
$this->connect_string .= "host={$sqlserver} ";
}
}
}
if ($database) {
$this->dbname = $database;
$this->connect_string .= "dbname={$database}";
}
$this->persistency = $persistency;
$this->db_connect_id = $this->persistency ? pg_pconnect($this->connect_string) : pg_connect($this->connect_string);
return $this->db_connect_id ? $this->db_connect_id : false;
}