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


PHP db2_pconnect函数代码示例

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


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

示例1: connect

 /**
  * This function connects to a DB2 database
  *
  * @param   string $host
  * @param   string $username
  * @param   string $password
  * @param   string $db_name
  * @return  boolean TRUE, if connected, otherwise FALSE
  * @access  public
  * @author  Thorsten Rinne <thorsten@phpmyfaq.de>
  * @since   2005-04-16
  */
 function connect($host, $user, $passwd, $db)
 {
     $this->conn = db2_pconnect($db, $user, $passwd, $this->options);
     if (false == $this->conn) {
         PMF_Db::errorPage(db2_conn_errormsg());
         die;
     }
     return true;
 }
开发者ID:nosch,项目名称:phpMyFAQ,代码行数:21,代码来源:Ibm_db2.php

示例2: __construct

 public function __construct(array $params, $username, $password, $driverOptions = array())
 {
     $isPersistant = isset($params['persistent']) && $params['persistent'] == true;
     if ($isPersistant) {
         $this->_conn = db2_pconnect($params['dbname'], $username, $password, $driverOptions);
     } else {
         $this->_conn = db2_connect($params['dbname'], $username, $password, $driverOptions);
     }
     if (!$this->_conn) {
         throw new DB2Exception(db2_conn_errormsg());
     }
 }
开发者ID:manish436,项目名称:zform,代码行数:12,代码来源:DB2Connection.php

示例3: dbQuery

function dbQuery($query, $show_errors = true, $all_results = true, $show_output = true)
{
    if ($show_errors) {
        error_reporting(E_ALL);
    } else {
        error_reporting(E_PARSE);
    }
    // Connect to the IBM DB2 database management system
    $link = db2_pconnect("testdb", "db2inst1", "testpass");
    if (!$link) {
        die(db2_conn_errormsg());
    }
    // Print results in HTML
    print "<html><body>\n";
    // Print SQL query to test sqlmap '--string' command line option
    //print "<b>SQL query:</b> " . $query . "<br>\n";
    // Perform SQL injection affected query
    $stmt = db2_prepare($link, $query);
    $result = db2_execute($stmt);
    if (!$result) {
        if ($show_errors) {
            print "<b>SQL error:</b> " . db2_stmt_errormsg($stmt) . "<br>\n";
        }
        exit(1);
    }
    if (!$show_output) {
        exit(1);
    }
    print "<b>SQL results:</b>\n";
    print "<table border=\"1\">\n";
    while ($line = db2_fetch_array($stmt)) {
        print "<tr>";
        foreach ($line as $col_value) {
            print "<td>" . $col_value . "</td>";
        }
        print "</tr>\n";
        if (!$all_results) {
            break;
        }
    }
    print "</table>\n";
    print "</body></html>";
}
开发者ID:dieface,项目名称:testenv,代码行数:43,代码来源:db2.inc.php

示例4: connect

 /**
  * connect()
  *
  * This function connects to a DB2 database
  *
  * @param   string $host
  * @param   string $username
  * @param   string $password
  * @param   string $db_name
  * @return  boolean TRUE, if connected, otherwise FALSE
  * @access  public
  * @author  Thorsten Rinne <thorsten@phpmyfaq.de>
  * @since   2005-04-16
  */
 function connect($host, $user, $passwd, $db)
 {
     $this->conn = db2_pconnect($db, $user, $passwd, $this->options);
     if (false == $this->conn) {
         print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
         print "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n";
         print "<head>\n";
         print "    <title>phpMyFAQ Error</title>\n";
         print "    <meta http-equiv=\"content-type\" content=\"application/xhtml+xml; charset=utf-8\" />\n";
         print "</head>\n";
         print "<body>\n";
         print "<p align=\"center\">The connection to the DB2 server could not be established.</p>\n";
         print "<p align=\"center\">The error message of the DB2 server:<br />" . db2_conn_errormsg() . "</p>\n";
         print "</body>\n";
         print "</html>";
         return false;
     }
     return true;
 }
开发者ID:juliogallardo1326,项目名称:proc,代码行数:33,代码来源:ibm_db2.php

示例5: connect

 /**
  * {@inheritdoc}
  */
 public function connect()
 {
     $config = $this->config;
     $config = array_merge($this->baseConfig, $config);
     $conn = "DATABASE='{$config['database']}';HOSTNAME='{$config['host']}';PORT={$config['port']};";
     $conn .= "PROTOCOL=TCPIP;UID={$config['username']};PWD={$config['password']};";
     if (!$config['persistent']) {
         $this->connection = db2_connect($conn, PGSQL_CONNECT_FORCE_NEW);
     } else {
         $this->connection = db2_pconnect($conn);
     }
     $this->connected = false;
     if ($this->connection) {
         $this->connected = true;
         $this->query('SET search_path TO ' . $config['schema']);
     }
     if (!empty($config['charset'])) {
         $this->setCharset($config['charset']);
     }
     return $this->connection;
 }
开发者ID:speedwork,项目名称:database,代码行数:24,代码来源:Db2Driver.php

示例6: open

 public function open()
 {
     if (!empty($GLOBALS['phpopenfw_db2_conn']) && is_resource($GLOBALS['phpopenfw_db2_conn']) && !$this->handle) {
         $this->handle = $GLOBALS['phpopenfw_db2_conn'];
     } else {
         if (!$this->handle) {
             $conn_str = "\n\t\t\t\tDRIVER={IBM DB2 ODBC DRIVER};\n\t\t\t\tDATABASE={$this->source};\n\t\t\t\tHOSTNAME={$this->server};\n\t\t\t\tPORT={$this->port};\n\t\t\t\tPROTOCOL=TCPIP;\n\t\t\t\tUID={$this->user};\n\t\t\t\tPWD={$this->pass};\n\t\t\t";
             // Connection String
             if ($this->conn_str !== false) {
                 $db_params = (string) $this->conn_str;
                 if ($this->persistent) {
                     $this->handle = !empty($this->options) ? db2_pconnect($db_params, '', '', $this->options) : db2_pconnect($db_params, '', '');
                 } else {
                     $this->handle = !empty($this->options) ? db2_connect($db_params, '', '', $this->options) : db2_connect($db_params, '', '');
                 }
             } else {
                 if ($this->persistent) {
                     $this->handle = !empty($this->options) ? db2_pconnect($this->source, $this->user, $this->pass, $this->options) : db2_pconnect($this->source, $this->user, $this->pass);
                 } else {
                     $this->handle = !empty($this->options) ? db2_connect($this->source, $this->user, $this->pass, $this->options) : db2_connect($this->source, $this->user, $this->pass);
                 }
             }
             if (db2_conn_errormsg()) {
                 $this->connection_error(db2_conn_errormsg());
                 $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 and Turn off Auto Commit?
     if (!$this->auto_commit && !$this->trans_started) {
         db2_autocommit($this->handle, DB2_AUTOCOMMIT_OFF);
         $this->start_trans();
     }
     return true;
 }
开发者ID:codifyllc,项目名称:phpopenfw,代码行数:40,代码来源:dt_db2.class.php

示例7: connect

 /**
  * 
  * 
  * @todo Throw in your "transport/adapter" framework for a real OO look and feel ....
  * Throw new Exception("Fail execute ($sql) ".db2_stmt_errormsg(),db2_stmt_error());
  * ... and retrieve via try/catch + Exception methods.
  *
  * @param $database
  * @param $user
  * @param $password
  * @param null $options 'persistent' is one option
  * @return bool
  */
 public function connect($database, $user, $password, $options = null)
 {
     // Compensate for older ibm_db2 driver that may not do this check.
     if ($user && empty($password)) {
         $this->setErrorCode('08001');
         $this->setErrorMsg('Authorization failure on distributed database connection attempt. SQLCODE=-30082');
         return false;
     }
     if ($options) {
         if (isset($options['persistent']) && $options['persistent']) {
             $conn = db2_pconnect($database, $user, $password);
         } else {
             $conn = db2_connect($database, $user, $password);
         }
         if (is_resource($conn)) {
             return $conn;
         }
     }
     $this->setErrorCode(db2_conn_error());
     $this->setErrorMsg(db2_conn_errormsg());
     return false;
 }
开发者ID:zendtech,项目名称:ibmitoolkit,代码行数:35,代码来源:Db2supp.php

示例8: open

 /**
  * This function opens a connection using the data source provided.
  *
  * @access public
  * @override
  * @throws Throwable_Database_Exception         indicates that there is problem with
  *                                              opening the connection
  *
  * @see http://www.php.net/manual/en/function.db2-connect.php
  * @see http://www.php.net/manual/en/function.db2-conn-error.php
  * @see http://www.zinox.com/node/132
  * @see http://www.ibm.com/developerworks/data/library/techarticle/dm-0505furlong/
  */
 public function open()
 {
     if (!$this->is_connected()) {
         $connection_string = 'DRIVER={IBM DB2 ODBC DRIVER};';
         $connection_string .= 'DATABASE=' . $this->data_source->database . ';';
         $connection_string .= 'HOSTNAME=' . $this->data_source->host . ';';
         $connection_string .= 'PORT=' . $this->data_source->port . ';';
         $connection_string .= 'PROTOCOL=TCPIP;';
         $connection_string .= 'UID=' . $this->data_source->username . ';';
         $connection_string .= 'PWD=' . $this->data_source->password . ';';
         $this->resource = $this->data_source->is_persistent() ? @db2_pconnect($connection_string, '', '') : @db2_connect($connection_string, '', '');
         if ($this->resource === FALSE) {
             throw new Throwable_Database_Exception('Message: Failed to establish connection. Reason: :reason', array(':reason' => @db2_conn_error()));
         }
         // "To use UTF-8 when talking to a DB2 instance, use the following command from the DB2 home at the command prompt: db2set DB2CODEPAGE=1208"
     }
 }
开发者ID:ruslankus,项目名称:invoice-crm,代码行数:30,代码来源:Standard.php

示例9: openUncataloged

 /**
  * Opens an uncataloged database connection, sets mConn
  */
 protected function openUncataloged($dbName, $user, $password, $server, $port)
 {
     $dsn = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE={$dbName};CHARSET=UTF-8;HOSTNAME={$server};PORT={$port};PROTOCOL=TCPIP;UID={$user};PWD={$password};";
     wfSuppressWarnings();
     $this->mConn = db2_pconnect($dsn, "", "", array());
     wfRestoreWarnings();
 }
开发者ID:nischayn22,项目名称:mediawiki-core,代码行数:10,代码来源:DatabaseIbm_db2.php

示例10: connect

 /**
  * Connecto to database
  *
  */
 private function connect()
 {
     switch ($this->model) {
         case "MYSQLI":
             if (!class_exists('mysqli')) {
                 throw new DatabaseException('Unsupported database model - ' . $this->model);
             }
             $this->dbh = new \mysqli($this->host, $this->user, $this->pass, $this->name, $this->port);
             if ($this->dbh->connect_error) {
                 throw new DatabaseException($this->dbh->connect_error, $this->dbh->connect_errno);
             }
             break;
         case "MYSQL_PDO":
             if (!in_array('mysql', \PDO::getAvailableDrivers())) {
                 throw new DatabaseException('Unsupported database model - ' . $this->model);
             }
             $dsn = "mysql:host=" . $this->host . ";port=" . $this->port . ";dbname=" . $this->name;
             try {
                 $this->dbh = new \PDO($dsn, $this->user, $this->pass, array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION));
             } catch (\PDOException $e) {
                 throw new DatabaseException($e->getMessage(), $e->getCode());
             }
             break;
         case "ORACLE_PDO":
             if (!in_array('oci', \PDO::getAvailableDrivers())) {
                 throw new DatabaseException('Unsupported database model - ' . $this->model);
             }
             $dsn = "oci:dbname=" . $this->host . ":" . $this->port . "/" . $this->name;
             try {
                 $this->dbh = new \PDO($dsn, $this->user, $this->pass, array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION));
             } catch (\PDOException $e) {
                 throw new DatabaseException($e->getMessage(), $e->getCode());
             }
             break;
         case "SQLITE_PDO":
             if (!in_array('sqlite', \PDO::getAvailableDrivers())) {
                 throw new DatabaseException('Unsupported database model - ' . $this->model);
             }
             $dsn = "sqlite:" . $this->name;
             try {
                 $this->dbh = new \PDO($dsn, $this->user, $this->pass, array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION));
             } catch (\PDOException $e) {
                 throw new DatabaseException($e->getMessage(), $e->getCode());
             }
             break;
         case "DB2":
             if (!function_exists('db2_pconnect')) {
                 throw new DatabaseException('Unsupported database model - ' . $this->model);
             }
             $dsn = "ibm:DRIVER={IBM DB2 ODBC DRIVER};DATABASE=" . $this->name;
             $dsn .= ";HOSTNAME=" . $this->host . ";PORT=" . $this->port . ";PROTOCOL=TCPIP;UID=" . $this->user . ";PWD=" . $this->pass . ";";
             $this->dbh = db2_pconnect($dsn, $this->user, $this->pass);
             if (!$this->dbh) {
                 throw new DatabaseException(db2_conn_errormsg());
             }
             break;
         case "DBLIB_PDO":
             if (!in_array('dblib', \PDO::getAvailableDrivers())) {
                 throw new DatabaseException('Unsupported database model - ' . $this->model);
             }
             $dsn = "dblib:host=" . $this->host . ":" . $this->port . ";dbname=" . $this->name;
             try {
                 $this->dbh = new \PDO($dsn, $this->user, $this->pass, array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION));
             } catch (\PDOException $e) {
                 throw new DatabaseException($e->getMessage(), $e->getCode());
             }
             break;
         case "POSTGRESQL":
             if (!function_exists('pg_connect')) {
                 throw new DatabaseException('Unsupported database model - ' . $this->model);
             }
             $dsn = "host=" . $this->host . " port=" . $this->port . " dbname=" . $this->name . " user=" . $this->user . " password=" . $this->pass;
             $this->dbh = @pg_connect($dsn);
             if ($this->dbh == false) {
                 throw new DatabaseException(pg_last_error());
             }
             break;
     }
 }
开发者ID:comodojo,项目名称:database,代码行数:83,代码来源:Database.php

示例11: connect

 public function connect(array $configOptions = null, $dieOnError = false)
 {
     global $sugar_config;
     if (is_null($configOptions)) {
         $configOptions = $sugar_config['dbconfig'];
     }
     if ($this->getOption('persistent')) {
         $persistConnection = true;
     } else {
         $persistConnection = false;
     }
     // Creating the connection string dynamically so that we can accommodate all scenarios
     // Starting with user and password as we always need these.
     $dsn = "UID=" . $configOptions['db_user_name'] . ";PWD=" . $configOptions['db_password'] . ";";
     $this->schema = strtoupper($configOptions['db_user_name']);
     // Converting to upper since DB2 expects it that way
     if (isset($configOptions['db_name']) && $configOptions['db_name'] != '') {
         $dsn = $dsn . "DATABASE=" . $configOptions['db_name'] . ";";
     }
     if (!isset($configOptions['db_host_name']) || $configOptions['db_host_name'] == '') {
         $configOptions['db_host_name'] = 'localhost';
     }
     // Connect to localhost by default
     $dsn = $dsn . "HOSTNAME=" . $configOptions['db_host_name'] . ";";
     if (!isset($configOptions['db_protocol']) || $configOptions['db_protocol'] == '') {
         $configOptions['db_protocol'] = 'TCPIP';
     }
     // Use TCPIP as default protocol
     $dsn = $dsn . "PROTOCOL=" . $configOptions['db_protocol'] . ";";
     if (!isset($configOptions['db_port']) || $configOptions['db_port'] == '') {
         $configOptions['db_port'] = '50000';
     }
     // Use 50000 as the default port
     $dsn = $dsn . "PORT=" . $configOptions['db_port'] . ";";
     if (!isset($configOptions['db_options'])) {
         $configOptions['db_options'] = array();
     }
     if ($persistConnection) {
         $this->database = db2_pconnect($dsn, '', '', $configOptions['db_options']);
         if (!$this->database) {
             $this->log->fatal(__CLASS__ . ": Persistent connection specified, but failed. Error: " . db2_conn_error() . ": " . db2_conn_errormsg());
         }
     }
     if (!$this->database) {
         $this->database = db2_connect($dsn, '', '', $configOptions['db_options']);
         if ($this->database && $persistConnection) {
             $_SESSION['administrator_error'] = "<b>Severe Performance Degradation: Persistent Database Connections " . "not working.  Please set \$sugar_config['dbconfigoption']['persistent'] to false " . "in your config.php file</b>";
         }
         if (!$this->database) {
             $this->log->fatal(__CLASS__ . ": Could not connect to Database with non-persistent connection. Error " . db2_conn_error() . ": " . db2_conn_errormsg());
         }
     }
     // Skipping check for statement errors as there is a bug in the DB2 driver
     // http://pecl.php.net/bugs/bug.php?id=22854
     // TODO take this skip out when the DB2 bug is fixed
     $this->ignoreErrors = true;
     if (!$this->checkError('Could Not Connect:', $dieOnError) && $this->database != false) {
         $this->log->info("connected to db");
         if (db2_autocommit($this->database, DB2_AUTOCOMMIT_OFF)) {
             $this->log->info("turned autocommit off");
         } else {
             $this->log->error("failed to turn autocommit off!");
         }
     }
     $this->ignoreErrors = false;
     $this->log->info("Connect:" . $this->database);
     return !empty($this->database);
 }
开发者ID:jglaine,项目名称:sugar761-ent,代码行数:68,代码来源:IBMDB2Manager.php

示例12: openUncataloged

 /**
  * Opens an uncataloged database connection, sets mConn
  */
 protected function openUncataloged($dbName, $user, $password, $server, $port)
 {
     $str = "DRIVER={IBM DB2 ODBC DRIVER};";
     $str .= "DATABASE={$dbName};";
     $str .= "HOSTNAME={$server};";
     // port was formerly validated to not be 0
     $str .= "PORT={$port};";
     $str .= "PROTOCOL=TCPIP;";
     $str .= "UID={$user};";
     $str .= "PWD={$password};";
     @($this->mConn = db2_pconnect($str, $user, $password));
 }
开发者ID:GodelDesign,项目名称:Godel,代码行数:15,代码来源:DatabaseIbm_db2.php

示例13: _pconnect

	function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename)
	{
		global $php_errormsg;

		if (!function_exists('db2_connect')) return null;

		// This needs to be set before the connect().
		// Replaces the odbc_binmode() call that was in Execute()
		ini_set('ibm_db2.binmode', $this->binmode);

		if (isset($php_errormsg)) $php_errormsg = '';
		$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';

		if ($argDatabasename && empty($argDSN)) {

			if (stripos($argDatabasename,'UID=') && stripos($argDatabasename,'PWD=')) $this->_connectionID = db2_pconnect($argDatabasename,null,null);
			else $this->_connectionID = db2_pconnect($argDatabasename,$argUsername,$argPassword);
		} else {
			if ($argDatabasename) $schema = $argDatabasename;
			if (stripos($argDSN,'UID=') && stripos($argDSN,'PWD=')) $this->_connectionID = db2_pconnect($argDSN,null,null);
			else $this->_connectionID = db2_pconnect($argDSN,$argUsername,$argPassword);
		}
		if (isset($php_errormsg)) $php_errormsg = '';

		$this->_errorMsg = @db2_conn_errormsg();
		if ($this->_connectionID && $this->autoRollback) @db2_rollback($this->_connectionID);
		if (isset($this->connectStmt)) $this->Execute($this->connectStmt);

		if ($this->_connectionID && isset($schema)) $this->Execute("SET SCHEMA=$schema");
		return $this->_connectionID != false;
	}
开发者ID:BackupTheBerlios,项目名称:oos-svn,代码行数:31,代码来源:adodb-db2.inc.php

示例14: db2_operate

function db2_operate($query, array $args = array(), array $options = array())
{
    global $db2_conn;
    if (!$db2_conn) {
        $conn_string = variable_get('simsauth_connect_string');
        $db2_conn = db2_pconnect($conn_string, '', '');
    }
    if (!empty($args)) {
        $stmt = db2_prepare($db2_conn, $query);
        if (!empty($options)) {
            $op_result = db2_set_option($stmt, $options, 2);
            if (!$op_result) {
                debug(db2_stmt_errormsg(), 'simsauth');
            }
        }
        $result = db2_execute($stmt, $args);
        if (!$result) {
            debug(db2_stmt_errormsg(), 'simsauth');
        } else {
            return TRUE;
        }
    } else {
        if (!empty($options)) {
            $op_result = db2_set_option($db2_conn, $options, 1);
            if (!$op_result) {
                debug(db2_conn_errormsg(), 'simsauth');
            }
        }
        $rs = db2_exec($db2_conn, $query);
        if (!$rs) {
            debug(db2_conn_errormsg(), 'simsauth');
        } else {
            return TRUE;
        }
    }
    return FALSE;
}
开发者ID:fosstp,项目名称:drupal4school,代码行数:37,代码来源:sims.api.php

示例15: connect

 /**
  * Connect
  *
  * @return ConnectionInterface
  */
 public function connect()
 {
     if (is_resource($this->resource)) {
         return $this;
     }
     // localize
     $p = $this->connectionParameters;
     // given a list of key names, test for existence in $p
     $findParameterValue = function (array $names) use($p) {
         foreach ($names as $name) {
             if (isset($p[$name])) {
                 return $p[$name];
             }
         }
         return null;
     };
     $database = $findParameterValue(array('database', 'db'));
     $username = $findParameterValue(array('username', 'uid', 'UID'));
     $password = $findParameterValue(array('password', 'pwd', 'PWD'));
     $isPersistent = $findParameterValue(array('persistent', 'PERSISTENT', 'Persistent'));
     $options = isset($p['driver_options']) ? $p['driver_options'] : array();
     if ($isPersistent) {
         $this->resource = db2_pconnect($database, $username, $password, $options);
     } else {
         $this->resource = db2_connect($database, $username, $password, $options);
     }
     if ($this->resource === false) {
         throw new Exception\RuntimeException(sprintf('%s: Unable to connect to database', __METHOD__));
     }
     return $this;
 }
开发者ID:eltondias,项目名称:Relogio,代码行数:36,代码来源:Connection.php


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