本文整理汇总了PHP中db2_connect函数的典型用法代码示例。如果您正苦于以下问题:PHP db2_connect函数的具体用法?PHP db2_connect怎么用?PHP db2_connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了db2_connect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _connect
function _connect($argDSN, $argUsername, $argPassword, $argDatabasename)
{
global $php_errormsg;
if (!function_exists('db2_connect')) {
ADOConnection::outp("Warning: The old ODBC based DB2 driver has been renamed 'odbc_db2'. This ADOdb driver calls PHP's native db2 extension.");
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 ($argDatabasename) {
$this->_connectionID = db2_connect($argDatabasename, $argUsername, $argPassword);
} else {
$this->_connectionID = db2_connect($argDSN, $argUsername, $argPassword);
}
if (isset($php_errormsg)) {
$php_errormsg = '';
}
// For db2_connect(), there is an optional 4th arg. If present, it must be
// an array of valid options. So far, we don't use them.
$this->_errorMsg = @db2_conn_errormsg();
if (isset($this->connectStmt)) {
$this->Execute($this->connectStmt);
}
return $this->_connectionID != false;
}
示例2: _connect
function _connect($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 ($argDatabasename) {
$this->_connectionID = db2_connect($argDatabasename, $argUsername, $argPassword);
} else {
$this->_connectionID = db2_connect($argDSN, $argUsername, $argPassword);
}
if (isset($php_errormsg)) {
$php_errormsg = '';
}
// For db2_connect(), there is an optional 4th arg. If present, it must be
// an array of valid options. So far, we don't use them.
$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
if (isset($this->connectStmt)) {
$this->Execute($this->connectStmt);
}
return $this->_connectionID != false;
}
示例3: connect
/**
* Open a connection to db
*/
public function connect()
{
$conn_string = "DATABASE=" . $this->dbname . ";HOSTNAME=" . $this->host . ";PORT=" . $this->port . ";PROTOCOL=TCPIP;UID=" . $this->user . ";PWD=" . $this->pwd . ";";
$this->conn = db2_connect($conn_string, '', '');
if (!$this->conn) {
trigger_error(db2_conn_errormsg(), E_USER_ERROR);
}
return $this->conn;
}
示例4: testPrepare
/**
* @covers Zend\Db\Adapter\Driver\IbmDb2\Statement::prepare
* @covers Zend\Db\Adapter\Driver\IbmDb2\Statement::isPrepared
*/
public function testPrepare()
{
$db2Resource = db2_connect($this->variables['database'], $this->variables['username'], $this->variables['password']);
$statement = new Statement();
$statement->initialize($db2Resource);
$this->assertFalse($statement->isPrepared());
$this->assertSame($statement, $statement->prepare("SELECT 'foo' FROM SYSIBM.SYSDUMMY1"));
$this->assertTrue($statement->isPrepared());
unset($resource, $db2Resource);
}
示例5: db2_test
function db2_test()
{
$conn_string = variable_get('simsauth_connect_string');
$db2_conn = db2_connect($conn_string, '', '');
if ($db2_conn) {
db2_close($db2_conn);
return TRUE;
} else {
return FALSE;
}
}
示例6: connect
/**
* Connects to DB2 database.
*
* @throws Exception
* @return resource
*/
public function connect()
{
$connection = null;
$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=" . Config::get('db.database_name') . ";HOSTNAME=" . Config::get('db.hostname') . ";PORT=" . Config::get('db.port') . ";PROTOCOL=TCPIP;UID=" . Config::get('db.user') . ";PWD=" . Config::get('db.password') . ";";
$connection = db2_connect($conn_string, '', '');
if (!$connection) {
$message = "Could not connect in the database: " . db2_stmt_errormsg();
throw new Exception($message);
}
return $connection;
}
示例7: __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());
}
}
示例8: testCreateStatement
public function testCreateStatement()
{
$driver = new IbmDb2(array());
$resource = db2_connect($this->variables['database'], $this->variables['username'], $this->variables['password']);
$stmtResource = db2_prepare($resource, 'SELECT 1 FROM SYSIBM.SYSDUMMY1');
$driver->getConnection()->setResource($resource);
$stmt = $driver->createStatement('SELECT 1 FROM SYSIBM.SYSDUMMY1');
$this->assertInstanceOf('Zend\\Db\\Adapter\\Driver\\IbmDb2\\Statement', $stmt);
$stmt = $driver->createStatement($stmtResource);
$this->assertInstanceOf('Zend\\Db\\Adapter\\Driver\\IbmDb2\\Statement', $stmt);
$stmt = $driver->createStatement();
$this->assertInstanceOf('Zend\\Db\\Adapter\\Driver\\IbmDb2\\Statement', $stmt);
$this->setExpectedException('Zend\\Db\\Adapter\\Exception\\InvalidArgumentException', 'only accepts an SQL string or a ibm_db2 resource');
$driver->createStatement(new \stdClass());
}
示例9: connect
function connect()
{
$currentEnv = getenv('SERVER_ENVIRONMENT');
$type = "Database";
$name = "";
$properties = getConfigByName($currentEnv, $type, $name);
if ($properties != "") {
$DB_USER = $properties[0]->username;
$DB_PASSWORD = $properties[0]->password;
$DB_HOST = $properties[0]->host;
$DB_NAME = $properties[0]->dbname;
$DB_TYPE = $properties[0]->type;
$conn = db2_connect($DB_NAME, $DB_USER, $DB_PASSWORD);
return $conn;
} else {
$conn = "";
return $conn;
}
}
示例10: 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;
}
示例11: 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;
}
示例12: 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;
}
示例13: otherdb
//.........这里部分代码省略.........
$db2query = isset($_POST['db2sql']) ? $_POST['db2sql'] : '';
$db2query = stripslashes($db2query);
print <<<END
<form method="POST" name="db2form" action="?s=gg&db=db2">
<div class="actall">Host:<input type="text" name="db2host" value="{$db2host}" style="width:100px">
Port:<input type="text" name="db2port" value="{$db2port}" style="width:60px">
User:<input type="text" name="db2user" value="{$db2user}" style="width:100px">
Pass:<input type="text" name="db2pass" value="{$db2pass}" style="width:100px">
Dbname:<input type="text" name="db2dbname" value="{$db2dbname}" style="width:100px"><br>
<script language="javascript">
function db2Full(i){
Str = new Array(4);
\tStr[0] = "";
\tStr[1] = "select schemaname from syscat.schemata;";
\tStr[2] = "select name from sysibm.systables;";
\tStr[3] = "select colname from syscat.columns where tabname='table_name';";
\tStr[4] = "db2 get db cfg for db_name;";
db2form.db2sql.value = Str[i];
return true;
}
</script>
<textarea name="db2sql" style="width:600px;height:200px;">{$db2query}</textarea><br>
<select onchange="return db2Full(options[selectedIndex].value)">
\t<option value="0" selected>ִ������</option>
\t<option value="1">���ݿ�</option>
\t<option value="1">����</option>
\t<option value="2">�ֶ�</option>
\t<option value="3">���ݿ�����</option>
</select>
<input type="hidden" name="action" value="db2query">
<input class="bt" type="submit" value="Query"></div></form>
END;
if ($myaction == 'db2query') {
$db2link = db2_connect($db2dbname, $db2user, $db2pass) or die(db2_conn_errormsg());
$db2result = db2_exec($db2link, $db2query) or die(db2_stmt_errormsg());
$db2row = db2_fetch_row($db2result);
echo '<font face="verdana"><table border="1" cellpadding="1" cellspacing="2">' . "\n<tr>\n";
for ($i = 0; $i < db2_num_fields($db2result); $i++) {
echo '<td><b>' . db2_field_name($db2result) . "</b></td>\n";
}
echo "</tr>\n";
while ($db2row = db2_fetch_row($db2result)) {
echo "<tr>\n";
for ($i = 0; $i < db2_num_fields($db2result); $i++) {
echo '<td>' . "{$db2row[$i]}" . '</td>';
}
echo "</tr>\n";
}
echo "</table></font>";
db2_free_result($db2result);
db2_close();
}
} elseif ($db == "fb") {
$fbhost = isset($_POST['fbhost']) ? $_POST['fbhost'] : 'localhost';
$fbpath = isset($_POST['fbpath']) ? $_POST['fbpath'] : '';
$fbpath = str_replace("\\\\", "\\", $fbpath);
$fbuser = isset($_POST['fbuser']) ? $_POST['fbuser'] : 'sysdba';
$fbpass = isset($_POST['fbpass']) ? $_POST['fbpass'] : 'masterkey';
$fbaction = isset($_POST['action']) ? $_POST['action'] : '';
$fbquery = isset($_POST['fbsql']) ? $_POST['fbsql'] : '';
$fbquery = stripslashes($fbquery);
print <<<END
<form method="POST" name="fbform" action="?s=gg&db=fb">
<div class="actall">Host:<input type="text" name="fbhost" value="{$fbhost}" style="width:100px">
Path:<input type="text" name="fbpath" value="{$fbpath}" style="width:100px">
User:<input type="text" name="fbuser" value="{$fbuser}" style="width:100px">
示例14: connect
/**
* Connects to the database using options in the given configuration array.
*
* @return boolean True if the database could be connected, else false
*/
function connect()
{
$config = $this->config;
$connect = 'db2_connect';
if ($config['persistent']) {
$connect = 'db2_pconnect';
}
$this->connected = false;
if ($config['cataloged']) {
$this->connection = $connect($config['database'], $config['login'], $config['password']);
} else {
$connString = sprintf("DRIVER={IBM DB2 ODBC DRIVER};DATABASE=%s;HOSTNAME=%s;PORT=%d;PROTOCOL=TCPIP;UID=%s;PWD=%s;", $config['database'], $config['hostname'], $config['port'], $config['login'], $config['password']);
$this->connection = db2_connect($connString, '', '');
}
if ($this->connection) {
$this->connected = true;
}
if ($config['schema'] !== '') {
$this->_execute('SET CURRENT SCHEMA = ' . $config['schema']);
}
return $this->connected;
}
示例15: __construct
/**
* Constructor for simpledb Proxy
* Use the values from the configuration file provided to create a PDO for the database
* Query the database to obtain column metadata and primary key
*
* @param string $target Target
* @param string $immediate_caller_directory Directory
* @param string $binding_config Config
*/
public function __construct($target, $immediate_caller_directory, $binding_config)
{
SCA::$logger->log('Entering constructor');
try {
$this->table = $target;
$this->config = SCA_Helper::mergeBindingIniAndConfig($binding_config, $immediate_caller_directory);
if (array_key_exists('username', $this->config)) {
$username = $this->config['username'];
} else {
$username = null;
}
if (array_key_exists('password', $this->config)) {
$password = $this->config['password'];
} else {
$password = null;
}
if (array_key_exists('namespace', $this->config)) {
$this->namespace = $this->config['namespace'];
}
if (array_key_exists('case', $this->config)) {
$this->case = $this->config['case'];
} else {
$this->case = 'lower';
}
if (!array_key_exists('dsn', $this->config)) {
throw new SCA_RuntimeException("Data source name should be specified");
}
$tableName = $this->table;
// Special processing for IBM databases:
// IBM table names can contain schema name as prefix
// Column metadata returned by pdo_ibm does not specify the primary key
// Hence primary key for IBM databases has to be obtained using
// db2_primary_key.
if (strpos($this->config["dsn"], "ibm:") === 0 || strpos($this->config["dsn"], "IBM:") === 0) {
$this->isIBM = true;
// Table could be of format schemaName.tableName
$schemaName = null;
if (($pos = strrpos($tableName, '.')) !== false) {
$schemaName = substr($tableName, 0, $pos);
$tableName = substr($tableName, $pos + 1);
}
// DSN for IBM databases can be a database name or a connection string
// Both can be passed onto db2_connect. Remove the dsn prefix if specified
$database = substr($this->config["dsn"], 4);
if (strpos($database, "dsn=") === 0 || strpos($database, "DSN=") === 0) {
$database = substr($database, 4);
}
// Need to make sure the name is in DB2 uppercase style
$db2TableName = strtoupper($tableName);
$conn = db2_connect($database, $username, $password);
$stmt = db2_primary_keys($conn, null, $schemaName, $db2TableName);
$keys = db2_fetch_array($stmt);
if (count($keys) > 3) {
$this->primary_key = $keys[3];
} else {
throw new SCA_RuntimeException("Table '{$tableName}' does not appear to have a primary key.");
}
}
$this->table_name = $this->_getName($tableName);
if ($username != null) {
$this->pdo = new PDO($this->config["dsn"], $username, $password, $this->config);
} else {
$this->pdo = new PDO($this->config["dsn"]);
}
$this->pdo_driver = $this->pdo->getAttribute(PDO::ATTR_DRIVER_NAME);
$stmt = $this->pdo->prepare('SELECT * FROM ' . $this->table);
if (!$stmt->execute()) {
throw new SCA_RuntimeException(self::_getPDOError($stmt, "select"));
}
$columns = array();
for ($i = 0; $i < $stmt->columnCount(); $i++) {
$meta = $stmt->getColumnMeta($i);
$name = $this->_getName($meta["name"]);
if (in_array("primary_key", $meta["flags"], true)) {
$this->primary_key = $name;
}
$columns[] = $name;
}
//$pk = $this->_getName($this->primary_key);
SCA::$logger->log("Table {$tableName} PrimaryKey {$this->primary_key}");
/*
$metadata = array(
'name' => $this->table_name,
'columns' => $columns,
'PK' => $pk
);
*/
$this->datafactory = SDO_DAS_DataFactory::getDataFactory();
// Define the model on the data factory (from the database)
$this->datafactory->addType(SCA_Bindings_simpledb_Proxy::ROOT_NS, SCA_Bindings_simpledb_Proxy::ROOT_TYPE);
$this->datafactory->addType($this->namespace, $this->table_name);
//.........这里部分代码省略.........