function db_closequery($qhandle) { if(function_exists("oci_free_statement")) oci_free_statement($qhandle); else ocifreestatement($qhandle); }
function free_result() { @ocifreestatement($this->Query_ID); $this->Query_ID = 0; }
function _free() { return ocifreestatement($this->_idResult); }
function &metaColumns($table, $normalize = true) { static $typeMap = array('VARCHAR' => 'C', 'VARCHAR2' => 'C', 'CHAR' => 'C', 'VARBINARY' => 'C', 'BINARY' => 'C', 'NCHAR' => 'C', 'NVARCHAR' => 'C', 'NVARCHAR2' => 'C', 'NCLOB' => 'X', 'LONG' => 'X', 'LONG VARCHAR' => 'X', 'CLOB' => 'X', 'LONG RAW' => 'B', 'LONG VARBINARY' => 'B', 'BLOB' => 'B', 'DATE' => 'D', 'TIMESTAMP' => 'T', 'INT' => 'I', 'SMALLINT' => 'I', 'INTEGER' => 'I'); $arr = explode('.', $table); $table = $this->qstr(strtoupper($arr[count($arr) - 1])); $stmt = $this->execute(sprintf($this->META_COLUMNS_SQL, $table)); if (!$stmt) { return false; } $retarr = array(); $row = array(); while (ocifetchinto($stmt, $row, OCI_NUM)) { $field = array(); if ($this->RESULT_FIELD_NAME_LOWER) { $field['name'] = strtolower($row[0]); } else { $field['name'] = $row[0]; } $field['type'] = preg_replace('/\\([0-9]+\\)/', '', $row[1]); $field['maxLength'] = $row[2]; $field['scale'] = isset($row[3]) ? $row[3] : null; if ($field['type'] == 'NUMBER') { if ($field['scale'] == 0) { $field['type'] = 'INT'; } $field['maxLength'] = isset($row[4]) ? $row[4] : null; } $field['notNull'] = strncmp($row[5], 'NOT', 3) === 0; $field['binary'] = strpos($field['type'], 'BLOB') !== false; $field['hasDefault'] = isset($row[6]); $field['defaultValue'] = isset($row[6]) ? $row[6] : null; $t = strtoupper($field['type']); if (isset($typeMap[$t])) { $field['simpleType'] = $typeMap[$t]; } else { $field['simpleType'] = 'N'; } $field['autoIncrement'] = false; $field['primaryKey'] = false; if ($normalize) { $retarr[strtoupper($field['name'])] = $field; } else { $retarr[$field['name']] = $field; } } ocifreestatement($stmt); // 确定主键字段 $ptab = 'USER_'; $sql = "SELECT /*+ RULE */ distinct b.column_name FROM {$ptab}CONSTRAINTS a, {$ptab}CONS_COLUMNS b WHERE ( UPPER(b.table_name) = ({$table})) AND (UPPER(a.table_name) = ({$table}) and a.constraint_type = 'P') AND (a.constraint_name = b.constraint_name)"; $stmt = $this->execute($sql); if ($stmt) { $row = array(); while (ocifetchinto($stmt, $row, OCI_NUM)) { $pkname = strtoupper($row[0]); if (isset($retarr[$pkname])) { $retarr[$pkname]['primaryKey'] = true; if ($retarr[$pkname]['type'] == 'INT') { $retarr[$pkname]['simpleType'] = 'R'; } } } ocifreestatement($stmt); } return $retarr; }
function addLogService($log, $idTrans = NULL) { $isNew = FALSE; if (empty($idTrans)) { $isNew = TRUE; $idTrans = $this->ora_get_sequence('SC_TRANS_KOMUNIKASI_DATA_WS'); } // Create connection to Oracle $userDb = $this->db->username; $passDb = $this->db->password; $hostname = $this->db->hostname; $conn = oci_connect($userDb, $passDb, $hostname); if ($conn) { if ($isNew == FALSE) { /* * update */ $query = "UPDATE TRANS_KOMUNIKASI_DATA_WS\n SET \n TKDW_PARAMETER = '" . $log['TKDW_PARAMETER'] . "',\n TKDW_STATUS = '" . $log['TKDW_STATUS'] . "',\n TKDW_LASTUPDATE = SYSDATE,\n TKDW_DATA = :TKDW_DATA,\n TKDW_RESULT = :TKDW_RESULT\n WHERE TKDW_ID = {$idTrans}\n "; $stmt = OCIParse($conn, $query); OCIBindByName($stmt, ':TKDW_DATA', $log['TKDW_DATA']); OCIBindByName($stmt, ':TKDW_RESULT', $log['TKDW_RESULT']); OCIExecute($stmt); ocifreestatement($stmt); } else { /* * insert baru */ $query = "INSERT INTO TRANS_KOMUNIKASI_DATA_WS \n (\n TKDW_ID, \n TKDW_NAMA_WS, \n TKDW_ALAMAT_SERVER, \n TKDW_PARAMETER, \n TKDW_STATUS, \n TKDW_TANGGAL, \n TKDW_LASTUPDATE, \n TKDW_USERUPDATE, \n TKDW_DATA, \n TKDW_RESULT\n )\n VALUES (\n {$idTrans}, \n '" . $log['TKDW_NAMA_WS'] . "', \n '" . $log['TKDW_ALAMAT_SERVER'] . "', \n '" . $log['TKDW_PARAMETER'] . "', \n '" . $log['TKDW_STATUS'] . "', \n SYSDATE, \n SYSDATE, \n '" . $log['TKDW_USERUPDATE'] . "', \n :TKDW_DATA, \n :TKDW_RESULT\n )"; $stmt = OCIParse($conn, $query); OCIBindByName($stmt, ':TKDW_DATA', $log['TKDW_DATA']); OCIBindByName($stmt, ':TKDW_RESULT', $log['TKDW_RESULT']); OCIExecute($stmt); ocifreestatement($stmt); } oci_close($conn); return $idTrans; } else { // $m = oci_error(); // echo $m['message'], "\n"; return NULL; } }
/** * Build db-specific report * @access private */ function _sql_report($mode, $query = '') { switch ($mode) { case 'start': $html_table = false; // Grab a plan table, any will do $sql = "SELECT table_name\n\t\t\t\t\tFROM USER_TABLES\n\t\t\t\t\tWHERE table_name LIKE '%PLAN_TABLE%'"; $stmt = ociparse($this->db_connect_id, $sql); ociexecute($stmt); $result = array(); if (ocifetchinto($stmt, $result, OCI_ASSOC + OCI_RETURN_NULLS)) { $table = $result['TABLE_NAME']; // This is the statement_id that will allow us to track the plan $statement_id = substr(md5($query), 0, 30); // Remove any stale plans $stmt2 = ociparse($this->db_connect_id, "DELETE FROM {$table} WHERE statement_id='{$statement_id}'"); ociexecute($stmt2); ocifreestatement($stmt2); // Explain the plan $sql = "EXPLAIN PLAN\n\t\t\t\t\t\tSET STATEMENT_ID = '{$statement_id}'\n\t\t\t\t\t\tFOR {$query}"; $stmt2 = ociparse($this->db_connect_id, $sql); ociexecute($stmt2); ocifreestatement($stmt2); // Get the data from the plan $sql = "SELECT operation, options, object_name, object_type, cardinality, cost\n\t\t\t\t\t\tFROM plan_table\n\t\t\t\t\t\tSTART WITH id = 0 AND statement_id = '{$statement_id}'\n\t\t\t\t\t\tCONNECT BY PRIOR id = parent_id\n\t\t\t\t\t\t\tAND statement_id = '{$statement_id}'"; $stmt2 = ociparse($this->db_connect_id, $sql); ociexecute($stmt2); $row = array(); while (ocifetchinto($stmt2, $row, OCI_ASSOC + OCI_RETURN_NULLS)) { $html_table = $this->sql_report('add_select_row', $query, $html_table, $row); } ocifreestatement($stmt2); // Remove the plan we just made, we delete them on request anyway $stmt2 = ociparse($this->db_connect_id, "DELETE FROM {$table} WHERE statement_id='{$statement_id}'"); ociexecute($stmt2); ocifreestatement($stmt2); } ocifreestatement($stmt); if ($html_table) { $this->html_hold .= '</table>'; } break; case 'fromcache': $endtime = explode(' ', microtime()); $endtime = $endtime[0] + $endtime[1]; $result = @ociparse($this->db_connect_id, $query); $success = @ociexecute($result, OCI_DEFAULT); $row = array(); while (@ocifetchinto($result, $row, OCI_ASSOC + OCI_RETURN_NULLS)) { // Take the time spent on parsing rows into account } @ocifreestatement($result); $splittime = explode(' ', microtime()); $splittime = $splittime[0] + $splittime[1]; $this->sql_report('record_fromcache', $query, $endtime, $splittime); break; } }
/** * Enter description here... * * @return unknown * @access public */ function fetchRow() { if ($this->_currentRow >= $this->_numRows) { ocifreestatement($this->_statementId); $this->_map = null; $this->_results = null; $this->_currentRow = null; $this->_numRows = null; return false; } $resultRow = array(); foreach ($this->_results[$this->_currentRow] as $index => $field) { list($table, $column) = $this->_map[$index]; if (strpos($column, ' count')) { $resultRow[0]['count'] = $field; } else { $resultRow[$table][$column] = $this->_results[$this->_currentRow][$index]; } } $this->_currentRow++; return $resultRow; }
function get_result() { $this->rows = array(); $this->columns = array(); $this->num_rows = $this->num_fields = 0; switch ($this->db) { case 'MySQL': $this->num_rows = @mysql_num_rows($this->res); $this->num_fields = @mysql_num_fields($this->res); while (false !== ($this->rows[] = @mysql_fetch_assoc($this->res))) { } @mysql_free_result($this->res); if ($this->num_rows) { $this->columns = @array_keys($this->rows[0]); return 1; } break; case 'MSSQL': $this->num_rows = @mssql_num_rows($this->res); $this->num_fields = @mssql_num_fields($this->res); while (false !== ($this->rows[] = @mssql_fetch_assoc($this->res))) { } @mssql_free_result($this->res); if ($this->num_rows) { $this->columns = @array_keys($this->rows[0]); return 1; } break; case 'PostgreSQL': $this->num_rows = @pg_num_rows($this->res); $this->num_fields = @pg_num_fields($this->res); while (false !== ($this->rows[] = @pg_fetch_assoc($this->res))) { } @pg_free_result($this->res); if ($this->num_rows) { $this->columns = @array_keys($this->rows[0]); return 1; } break; case 'Oracle': $this->num_fields = @ocinumcols($this->res); while (false !== ($this->rows[] = @oci_fetch_assoc($this->res))) { $this->num_rows++; } @ocifreestatement($this->res); if ($this->num_rows) { $this->columns = @array_keys($this->rows[0]); return 1; } break; } return 0; }
function FreeResult($rsLookUp) { return ocifreestatement($rsLookUp); }
/** * @desc Close all output binds cursor that remain opened * * @author Eric TINOCO <*****@*****.**> * * @date 2009/04/23 * @version 1.0 * * @return void * */ function _closeOutputBindCursors() { if (count($this->aOutputBinds) > 0) { foreach ($this->aOutputBinds as &$aBind) { if ($aBind['TYPE'] === $this->_iCursorType && is_resource($aBind['VALUE'])) { @ocifreestatement($aBind['VALUE']); } } } }
function currentid($seqname) { $this->connect(); $Query_ID = @ociparse($this->Link_ID, "SELECT {$seqname}.CURRVAL FROM DUAL"); @ociexecute($Query_ID); if (@ocifetch($Query_ID)) { $current_id = ociresult($Query_ID, "CURRVAL"); } else { $current_id = 0; } ocifreestatement($Query_ID); return $current_id; }
public function sqlReport($query) { $sHtml = ''; $html_table = false; // Grab a plan table, any will do $sql = "SELECT table_name\n\t\t\t\t\tFROM USER_TABLES\n\t\t\t\t\tWHERE table_name LIKE '%PLAN_TABLE%'"; $stmt = ociparse($this->_hMaster, $sql); ociexecute($stmt); $result = array(); if (ocifetchinto($stmt, $result, OCI_ASSOC + OCI_RETURN_NULLS)) { $table = $result['TABLE_NAME']; // This is the statement_id that will allow us to track the plan $statement_id = substr(md5($query), 0, 30); // Remove any stale plans $stmt2 = ociparse($this->_hMaster, "DELETE FROM {$table} WHERE statement_id='{$statement_id}'"); ociexecute($stmt2); ocifreestatement($stmt2); // Explain the plan $sql = "EXPLAIN PLAN\n\t\t\t\t\t\tSET STATEMENT_ID = '{$statement_id}'\n\t\t\t\t\t\tFOR {$query}"; $stmt2 = ociparse($this->_hMaster, $sql); ociexecute($stmt2); ocifreestatement($stmt2); // Get the data from the plan $sql = "SELECT operation, options, object_name, object_type, cardinality, cost\n\t\t\t\t\t\tFROM plan_table\n\t\t\t\t\t\tSTART WITH id = 0 AND statement_id = '{$statement_id}'\n\t\t\t\t\t\tCONNECT BY PRIOR id = parent_id\n\t\t\t\t\t\t\tAND statement_id = '{$statement_id}'"; $stmt2 = ociparse($this->_hMaster, $sql); ociexecute($stmt2); $row = array(); while (ocifetchinto($stmt2, $row, OCI_ASSOC + OCI_RETURN_NULLS)) { list($html_table, $sData) = Phpfox_Debug::addRow($html_table, $row); $sHtml .= $sData; } ocifreestatement($stmt2); // Remove the plan we just made, we delete them on request anyway $stmt2 = ociparse($this->_hMaster, "DELETE FROM {$table} WHERE statement_id='{$statement_id}'"); ociexecute($stmt2); ocifreestatement($stmt2); } ocifreestatement($stmt); if ($html_table) { $sHtml .= '</table>'; } return $sHtml; }
/** * db_free_result() - Frees a database result properly * * @param string Query result set handle */ function db_free_result($qhandle) { global $sys_db_results; unset($sys_db_results[$qhandle]); return @ocifreestatement($qhandle); }
/** * Free the internal resources associated with a prepared query. * * @param $stmt oci8 statement identifier * * @return bool TRUE on success, FALSE if $result is invalid */ function freePrepared($stmt) { if (!is_resource($stmt)) { return false; } ocifreestatement($stmt); unset($this->prepare_tokens[(int) $stmt]); unset($this->prepare_types[(int) $stmt]); unset($this->manip_query[(int) $stmt]); return true; }
/** * Free resources associated with a query result set * @param Mixed qHanle The query handle */ public function closeQuery($qHanle) { if (function_exists("oci_free_statement")) { oci_free_statement($qHanle); } else { ocifreestatement($qHanle); } }
// close cursor $outrefc = ocinewcursor($conn); //Declare cursor variable $mycursor = ociparse($conn, "begin getPotisions(:curs,'{$alin2}'); end;"); // prepare procedure call ocibindbyname($mycursor, ':curs', $outrefc, -1, OCI_B_CURSOR); // bind procedure parameters $ret = ociexecute($mycursor); // Execute function $ret = ociexecute($outrefc); // Execute cursor $nrows = ocifetchstatement($outrefc, $pos2); // fetch data from cursor ocifreestatement($mycursor); // close procedure call ocifreestatement($outrefc); // close cursor for ($p = 0; $p < count($pos2["POSICION"]); $p++) { $posicion1 = $pos1["POSICION"][$p]; $nombre1 = $pos1["NOMBRE"][$p]; $posicion2 = $pos2["POSICION"][$p]; $nombre2 = $pos2["NOMBRE"][$p]; echo "<div class='Align_Row'>\n <div class='Player_Photo'>.</div>\n <div class='Player_Info_Box'>\n <div class='Player_Name'> {$nombre1} </div>\n <div class='Player_Position'> {$posicion1}</div>\n </div>\n </div> "; } echo "</div>\n <div id='ColumTeamB' class='Column'>"; for ($p = 0; $p < count($pos2["POSICION"]); $p++) { $posicion1 = $pos1["POSICION"][$p]; $nombre1 = $pos1["NOMBRE"][$p]; $posicion2 = $pos2["POSICION"][$p]; $nombre2 = $pos2["NOMBRE"][$p]; echo "<div class='Align_Row'>\n <div class='Player_Photo'>.</div>\n <div class='Player_Info_Box'>\n <div class='Player_Name'> {$nombre2} </div>\n <div class='Player_Position'> {$posicion2} </div>\n </div>\n </div> ";
/** * 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 = @ociparse($this->db_connect_id, $query); $success = @ociexecute($result, OCI_DEFAULT); $row = array(); while (@ocifetchinto($result, $row, OCI_ASSOC + OCI_RETURN_NULLS)) { // Take the time spent on parsing rows into account } @ocifreestatement($result); $splittime = explode(' ', microtime()); $splittime = $splittime[0] + $splittime[1]; $this->sql_report('record_fromcache', $query, $endtime, $splittime); break; } }
/** * Frees the internal resources associated with a prepared query * * @param resource $stmt the prepared statement's resource * @param bool $free_resource should the PHP resource be freed too? * Use false if you need to get data * from the result set later. * * @return bool TRUE on success, FALSE if $result is invalid * * @see DB_oci8::prepare() */ function freePrepared($stmt, $free_resource = true) { if (!is_resource($stmt)) { return false; } if ($free_resource) { @ocifreestatement($stmt); } if (isset($this->prepare_types[(int) $stmt])) { unset($this->prepare_types[(int) $stmt]); unset($this->manip_query[(int) $stmt]); } else { return false; } return true; }
print(" </tr>\n"); for($i = 0; $i < $nrows; $i++) { print(" <tr valign=\"center\">\n"); print(" <td class=\"p2k\" rowspan=\"3\" align=\"right\">\n ".($i + 1).".\n </td>\n"); print(" <td class=\"p2k\">\n <b>\n ".$results['FILENAME'][$i]."\n </b>\n </td>\n"); print(" </tr>\n <tr>\n"); print(" <td class=\"p2k\">\n <script language=\"JavaScript\">\n <!--\n document.write(convert(".$results['CRONTIME'][$i]."));\n // -->\n </script>\n </td>\n"); print(" </tr>\n <tr>\n"); print(" <td class=\"p2k\">\n <div id=\"stail".str_pad($i + 1, 3, "0", STR_PAD_LEFT)."\"".($flag = ($_GET['mask']{$i} == "1")? " class=\"inv\"": "").">\n <pre>".$results['SHORT_TAIL'][$i]."</pre>\n <button onClick=\"expand(this.parentNode);\">\n expand ".($i + 1)."\n </button>\n </div>\n"); print(" <div id=\"ltail".str_pad($i + 1, 3, "0", STR_PAD_LEFT)."\"".(!$flag? " class=\"inv\"": "").">\n <textarea readonly=\"readonly\" wrap=\"off\">".$results['LONG_TAIL'][$i]."</textarea>\n <br>\n <br>\n <button onClick=\"shrink(this.parentNode);\">\n shrink ".($i + 1)."\n </button>\n </div>\n </td>\n"); print(" </tr>\n"); } print("</table>\n"); } else print("<p class=\"bo\">\n No PopCon cronjob tails recorded!\n</p>\n"); ocifreestatement($stmt); ocilogoff($conn); $svr = $svrlog; $apl = "mon"; require($path."auth.inc"); $conn = ocilogon($usr, $pwd, $svr); require($path."geoip.inc"); $gi = geoip_open("geoip.dat", GEOIP_STANDARD); ociexecute(ociparse($conn, "insert into $usr.mon_log (domain, ip, country, browser, kind) values ('".strtolower(gethostbyaddr("$REMOTE_ADDR"))."', '$REMOTE_ADDR', '".geoip_country_name_by_addr($gi, $REMOTE_ADDR)."', '$HTTP_USER_AGENT', 'T')")); ocicommit($conn); geoip_close($gi); ocilogoff($conn); } else oraconnecterror(); </script>
} else { echo "<table width=100%><tr>"; for ($j = 1; $j <= @ocinumcols($stat); $j++) { echo "<td bgcolor=#cccccc><font face=Verdana size=-2><b> " . htmlspecialchars(@ocicolumnname($stat, $j)) . " </b></font></td>"; } echo "</tr>"; while (ocifetch($stat)) { echo "<tr>"; for ($j = 1; $j <= @ocinumcols($stat); $j++) { echo "<td><font face=Verdana size=-2> " . htmlspecialchars(@ociresult($stat, $j)) . " </font></td>"; } echo "</tr>"; } echo "</table><br>"; } @ocifreestatement($stat); } } } @ocilogoff($db); } break; } echo "<form name=form method=POST>"; echo in('hidden', 'db', 0, $_POST['db']); echo in('hidden', 'db_port', 0, $_POST['db_port']); echo in('hidden', 'mysql_l', 0, $_POST['mysql_l']); echo in('hidden', 'mysql_p', 0, $_POST['mysql_p']); echo in('hidden', 'mysql_db', 0, $_POST['mysql_db']); echo in('hidden', 'cmd', 0, 'db_query'); echo "<div align=center><textarea cols=65 rows=10 name=db_query>" . (!empty($_POST['db_query']) ? $_POST['db_query'] : "SHOW DATABASES;\nSELECT * FROM user;") . "</textarea><br><input type=submit name=submit value=\" Run SQL query \"></div><br><br>";
/** * Frees the memory for this result. * @access public * @return void */ function free() { ocifreestatement($this->_resourceId); }
/** * Free the result * * @return null */ function free_result() { if (is_resource($this->result_id)) { ocifreestatement($this->result_id); $this->result_id = FALSE; } }
ocicolumnprecision(); ocicolumnscale(); ocicolumnsize(); ocicolumntype(); ocicolumntyperaw(); ocicommit(); ocidefinebyname(); ocierror(); ociexecute(); ocifetch(); ocifetchinto(); ocifetchstatement(); ocifreecollection(); ocifreecursor(); ocifreedesc(); ocifreestatement(); ociinternaldebug(); ociloadlob(); ocilogoff(); ocilogon(); ocinewcollection(); ocinewcursor(); ocinewdescriptor(); ocinlogon(); ocinumcols(); ociparse(); ociplogon(); ociresult(); ocirollback(); ocirowcount(); ocisavelob();