当前位置: 首页>>代码示例>>PHP>>正文


PHP pg_connect函数代码示例

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


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

示例1: db_connect

function db_connect($host, $user, $pass, $db, $type, $port = false)
{
    if ($type == "pgsql") {
        $string = "dbname={$db} user={$user}";
        if ($pass) {
            $string .= " password={$pass}";
        }
        if ($host) {
            $string .= " host={$host}";
        }
        if ($port) {
            $string = "{$string} port=" . $port;
        }
        $link = pg_connect($string);
        return $link;
    }
    if ($type == "mysql") {
        if (function_exists("mysqli_connect")) {
            if ($port) {
                return mysqli_connect($host, $user, $pass, $db, $port);
            }
            return mysqli_connect($host, $user, $pass, $db);
        }
        $link = mysql_connect($host, $user, $pass);
        if ($link) {
            $result = mysql_select_db($db, $link);
            if ($result) {
                return $link;
            }
        }
    }
}
开发者ID:adrianpietka,项目名称:bfrss,代码行数:32,代码来源:installer_functions.php

示例2: conectar_bodega

 public function conectar_bodega()
 {
     if (!isset($this->conexion)) {
         $this->conexion = pg_connect("host=localhost port=5432 dbname=proyecto user=administrador password=123456") or die("Error de conexion. " . pg_last_error());
         return $this->conexion;
     }
 }
开发者ID:japeto,项目名称:PollSystem,代码行数:7,代码来源:db.class_bodega.php

示例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. ");
     }
 }
开发者ID:TheProjecter,项目名称:skeleton,代码行数:33,代码来源:Postgres.php

示例4: db_connect

 function db_connect($connection_name = false)
 {
     if ($this->db) {
         return true;
     }
     // Choose what to connect to
     if ($connection_name && $GLOBALS['AR_DB_CONFIG'][$connection_name]) {
         $this->default = $GLOBALS['AR_DB_CONFIG'][$connection_name];
         $this->db_connection = $connection_name;
     } elseif ($this->db_connection && $GLOBALS['AR_DB_CONFIG'][$this->db_connection]) {
         $this->default = $GLOBALS['AR_DB_CONFIG'][$this->db_connection];
     } else {
         $this->default = $GLOBALS['AR_DB_CONFIG'][AR_DEFAULT_DB];
         $this->db_connection = AR_DEFAULT_DB;
     }
     // Get outta here if we have no good setting
     if (!$this->default['hostname']) {
         die('Please setup database.ini');
     }
     // Connect
     if ($this->db = pg_connect("host={$this->default['hostname']} dbname={$this->default['database']} user={$this->default['login']} password={$this->default['password']}")) {
         // Connected !
     } else {
         die('Unable to connect to database: ' . $this->default['database']);
     }
     return true;
 }
开发者ID:esconsut1,项目名称:php-rails-clone,代码行数:27,代码来源:ar_postgresql.php

示例5: connect

 public function connect()
 {
     $this->linkid = pg_connect("host={$this->_config['host']}\n                                    port={$this->_config['port']}\n                                    dbname={$this->_config['database']}\n                                    user={$this->_config['user']}\n                                    password={$this->_config['password']}");
     if (!$this->linkid) {
         throw new Exception("Could not connect to PostgreSQL server.");
     }
 }
开发者ID:sdgdsffdsfff,项目名称:data_web,代码行数:7,代码来源:Pgsql.php

示例6: __construct

 public function __construct()
 {
     // - Connexion à la BD
     require_once "constantes.inc.php";
     // - connexion à la base de données
     $this->db_connect = pg_connect("host=" . HOSTNAME . " dbname=" . BASE . " user=" . LOGIN . " password=" . PASSWORD);
 }
开发者ID:domiboo,项目名称:libertribes_fromneosys,代码行数:7,代码来源:class_connexion.php

示例7: connect

 function connect()
 {
     $this->hostName = MY_HOST;
     $this->port = MY_PORT;
     $this->userName = MY_USER;
     $this->password = MY_PASS;
     $this->databaseName = MY_BD;
     // build connection string based on internal settings.
     $connStr = '';
     $this->hostName != '' ? $connStr .= "host=" . $this->hostName . " " : ($connStr = $connStr);
     $this->port != '' ? $connStr .= "port=" . $this->port . " " : ($connStr = $connStr);
     $this->databaseName != '' ? $connStr .= "dbname=" . $this->databaseName . " " : ($connStr = $connStr);
     $this->userName != '' ? $connStr .= "user=" . $this->userName . " " : ($connStr = $connStr);
     $this->password != '' ? $connStr .= "password=" . $this->password . " " : ($connStr = $connStr);
     $connStr = trim($connStr);
     $connID = pg_connect($connStr);
     if ($connID != "") {
         $this->connectionID = $connID;
         $this->exec("set datestyle='ISO'", array());
         $this->exec("set time zone 'America/Santiago'", array());
         return $this->connectionID;
     } else {
         // FATAL ERROR - CONNECTI0N ERROR
         $this->errorCode = -1;
         $this->connectionID = -1;
         return 0;
     }
 }
开发者ID:jnaxo,项目名称:bd13,代码行数:28,代码来源:db.php

示例8: db_connect

function db_connect($dbtype = 'mysql')
{
    $dbhost = 'localhost';
    $dbuser = 'analytics';
    $dbpass = '4T4r!an@lyt5';
    if ($dbtype == 'pear') {
        $dsn = array('phptype' => 'mysql', 'username' => $dbuser, 'password' => $dbpass, 'hostspec' => $dbhost);
        $options = array('debug' => 2, 'portability' => MDB2_PORTABILITY_ALL);
        // uses MDB2::factory() to create the instance
        // and also attempts to connect to the host
        $mdb2 = MDB2::connect($dsn, $options);
        if (PEAR::isError($mdb2)) {
            error($mdb2->getMessage());
        }
        return $mdb2;
    } else {
        if ($dbtype == 'mysql') {
            $mysql_conn = mysqli_connect($dbhost, $dbuser, $dbpass);
            if (mysqli_connect_errno()) {
                error("MySQL : Connect failed: %s\n" . mysqli_connect_error());
            }
            return $mysql_conn;
        } else {
            if ($dbtype == 'postgres') {
                $postgres_conn = pg_connect("host={$dbhost} user={$dbuser} password={$dbpass}");
                if (!$postgres_conn) {
                    error("PostGres : Connect failed: %s");
                }
                return $postgres_conn;
            }
        }
    }
}
开发者ID:rjevansatari,项目名称:Analytics,代码行数:33,代码来源:db.php

示例9: connect

 /**
  * This is the connect function that tries to create a postgresql connection, and set the correct character set.
  */
 protected function connect()
 {
     if (!function_exists("pg_connect")) {
         throw new DatabaseException("The function pg_connect is not available! Please install the postgresql php module.");
     }
     $connection_string = "";
     if ($this->host) {
         $connection_string .= "host='" . pg_escape_string($this->host) . "' ";
     }
     if ($this->port) {
         $connection_string .= "port='" . pg_escape_string($this->port) . "' ";
     }
     if ($this->dbname) {
         $connection_string .= "dbname='" . pg_escape_string($this->dbname) . "' ";
     }
     if ($this->user) {
         $connection_string .= "user='" . pg_escape_string($this->user) . "' ";
     }
     if ($this->password) {
         $connection_string .= "password='" . pg_escape_string($this->password) . "' ";
     }
     $this->resource = pg_connect($connection_string);
     if (!$this->resource) {
         throw new DatabaseException("Sorry, impossible to connect to the server with this connection string: '" . $this->getConnectionString() . "'.");
     }
     $this->connected = true;
     pg_set_client_encoding($this->resource, $this->charsetName);
     if ($this->searchPath) {
         $this->query('set search_path to "' . pg_escape_string($this->searchPath) . '"');
     }
     return true;
 }
开发者ID:enyo,项目名称:rincewind,代码行数:35,代码来源:Postgresql.php

示例10: __construct

 function __construct()
 {
     /*   $ORIONDBCFG_DB_host = "localhost";
        $ORIONDBCFG_DB_user = "doctool";
        $ORIONDBCFG_DB_password = ".Whyareo";
        $ORIONDBCFG_DB_dbname = "toelatingsexamen"; */
     $connstring = "";
     if ($ORIONDB_CFG_DB_host) {
         $connstring .= "host=" . $ORIONDB_CFG_DB_host . " ";
     }
     if ($ORIONDB_CFG_DB_dbname) {
         $connstring .= "dbname=" . $ORIONDB_CFG_DB_dbname . " ";
     }
     if ($ORIONDB_CFG_DB_user) {
         $connstring .= "user=" . $ORIONDB_CFG_DB_user . " ";
     }
     if ($ORIONDB_CFG_DB_password) {
         $connstring .= "password=" . $ORIONDB_CFG_DB_password . " ";
     }
     //$dbconn3 = pg_connect("host=sheep port=5432 dbname=mary user=lamb password=foo");
     //connect to a database named "mary" on the host "sheep" with a username and password
     $this->dbconnection = pg_connect($connstring) or die("Database connection failed");
     // get tables
     $query = "SELECT NULL AS nspname, c.relname, \n\t\t\t\t\t(SELECT usename FROM pg_user u WHERE u.usesysid=c.relowner) AS relowner,\n\t\t\t\t\t(SELECT description FROM pg_description pd WHERE c.oid=pd.objoid) AS relcomment,\n\t\t\t\t\treltuples::bigint AS reltuples\n\t\t\t\tFROM pg_class c\n\t\t\t\tWHERE c.relkind='r'\n\t\t\t\t\tAND NOT EXISTS (SELECT 1 FROM pg_rewrite r WHERE r.ev_class = c.oid AND r.ev_type = '1')\n\t\t\t\t\tAND c.relname NOT LIKE 'pg@_%' ESCAPE '@' \n\t\t\t\t\tAND c.relname NOT LIKE 'sql@_%' ESCAPE '@'\n\t\t\t\tORDER BY relname";
 }
开发者ID:beOn,项目名称:orion-db,代码行数:25,代码来源:OrionDB_PostgreSQL.php

示例11: control

function control()
{
    global $result, $input, $userID;
    $conn = pg_connect("host=postgredb.ctnfr2pmdvmf.us-west-2.rds.amazonaws.com port=5432 dbname=postgreDB user=postgreuser password=6089qwerty");
    if (!$conn) {
        echo "denied, an error occurred about connection.\n";
        exit;
    }
    $query = "SELECT USERNAME,USERID FROM PALUSER WHERE USERNAME LIKE '{$input}%' AND USERID != '{$userID}'";
    $result = pg_query($conn, $query);
    if (!$result) {
        echo "denied, an error occurred about query.\n";
        return 0;
    }
    $names = "";
    $ids = "";
    $first = true;
    while ($row = pg_fetch_row($result)) {
        if ($first) {
            $names = $row[0];
            $ids = $row[1];
            $first = false;
        } else {
            $names = $names . " " . $row[0];
            $ids = $ids . " " . $row[1];
        }
    }
    if ($ids == "") {
        echo "denied, empty result";
    }
    return $names . " " . $ids;
}
开发者ID:serten,项目名称:ProjectPAL,代码行数:32,代码来源:searchFriends_postgre.php

示例12: dbconnect

 private function dbconnect()
 {
     //$dbconn = pg_connect("host=" . DB_HOST . " dbname=" . DB_DB . " user=" . DB_USER . " password=" . DB_PASSWORD)
     //or die('<br>Could not connect: ' . pg_last_error());
     $dbconn = pg_connect("host=turing.centre.edu dbname=theaterDB user=visitorDrama password=Costumes4All") or die('Could not connect: ' . pg_last_error());
     return $dbconn;
 }
开发者ID:sapocaly,项目名称:centre-theater,代码行数:7,代码来源:DAL.php

示例13: connect

 public function connect($connectionString)
 {
     $this->connection = \pg_connect($connectionString);
     if (!$this->connection) {
         throw new \Exception('Failed to connect: ' . \pg_last_error($this->connection));
     }
 }
开发者ID:nicksamie,项目名称:dbadashboard,代码行数:7,代码来源:redshiftconnect.php

示例14: transform

function transform($x, $y, $oldEPSG, $newEPSG)
{
    if (is_null($x) || !is_numeric($x) || is_null($y) || !is_numeric($y) || is_null($oldEPSG) || !is_numeric($oldEPSG) || is_null($newEPSG) || !is_numeric($newEPSG)) {
        return null;
    }
    if (SYS_DBTYPE == 'pgsql') {
        $con = db_connect(DBSERVER, OWNER, PW);
        $sqlMinx = "SELECT X(transform(GeometryFromText('POINT(" . pg_escape_string($x) . " " . pg_escape_string($y) . ")'," . pg_escape_string($oldEPSG) . ")," . pg_escape_string($newEPSG) . ")) as minx";
        $resMinx = db_query($sqlMinx);
        $minx = floatval(db_result($resMinx, 0, "minx"));
        $sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(" . pg_escape_string($x) . " " . pg_escape_string($y) . ")'," . pg_escape_string($oldEPSG) . ")," . pg_escape_string($newEPSG) . ")) as miny";
        $resMiny = db_query($sqlMiny);
        $miny = floatval(db_result($resMiny, 0, "miny"));
    } else {
        $con_string = "host=" . GEOS_DBSERVER . " port=" . GEOS_PORT . " dbname=" . GEOS_DB . "user=" . GEOS_OWNER . "password=" . GEOS_PW;
        $con = pg_connect($con_string) or die("Error while connecting database");
        /*
         * @security_patch sqli done
         */
        $sqlMinx = "SELECT X(transform(GeometryFromText('POINT(" . pg_escape_string($x) . " " . pg_escape_string($y) . ")'," . pg_escape_string($oldEPSG) . ")," . pg_escape_string($newEPSG) . ")) as minx";
        $resMinx = pg_query($con, $sqlMinx);
        $minx = floatval(pg_fetch_result($resMinx, 0, "minx"));
        $sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(" . pg_escape_string($x) . " " . pg_escape_string($y) . ")'," . pg_escape_string($oldEPSG) . ")," . pg_escape_string($newEPSG) . ")) as miny";
        $resMiny = pg_query($con, $sqlMiny);
        $miny = floatval(pg_fetch_result($resMiny, 0, "miny"));
    }
    return array("x" => $minx, "y" => $miny);
}
开发者ID:bfpi,项目名称:klarschiff-frontend-mit-mapbender,代码行数:28,代码来源:mod_coordsLookup_server.php

示例15: connect

function connect($db_conn_string, $db_search_path)
{
    global $conn;
    $conn = pg_connect($db_conn_string) or die('Could not connect: ' . pg_last_error());
    pg_query("SET search_path TO {$db_search_path}");
    return $conn;
}
开发者ID:johnpyeatt,项目名称:nominatiny,代码行数:7,代码来源:dbutils.inc.php


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