/** * Base query method * * @param string $query Contains the SQL query which shall be executed * @param int $cache_ttl Either 0 to avoid caching or the time in seconds which the result shall be kept in cache * @return mixed When casted to bool the returned value returns true on success and false on failure * * @access public */ function sql_query($query = '', $cache_ttl = 0) { if ($query != '') { global $cache; // EXPLAIN only in extra debug mode if (defined('DEBUG_EXTRA')) { $this->sql_report('start', $query); } $this->last_query_text = $query; $this->query_result = $cache_ttl && method_exists($cache, 'sql_load') ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) { $in_transaction = false; if (!$this->transaction) { $this->sql_transaction('begin'); } else { $in_transaction = true; } $array = array(); // We overcome Oracle's 4000 char limit by binding vars if (strlen($query) > 4000) { if (preg_match('/^(INSERT INTO[^(]++)\\(([^()]+)\\) VALUES[^(]++\\((.*?)\\)$/sU', $query, $regs)) { if (strlen($regs[3]) > 4000) { $cols = explode(', ', $regs[2]); preg_match_all('/\'(?:[^\']++|\'\')*+\'|[\\d-.]+/', $regs[3], $vals, PREG_PATTERN_ORDER); if (sizeof($cols) !== sizeof($vals)) { // Try to replace some common data we know is from our restore script or from other sources $regs[3] = str_replace("'||chr(47)||'", '/', $regs[3]); $_vals = explode(', ', $regs[3]); $vals = array(); $is_in_val = false; $i = 0; $string = ''; foreach ($_vals as $value) { if (strpos($value, "'") === false && !$is_in_val) { $vals[$i++] = $value; continue; } if (substr($value, -1) === "'") { $vals[$i] = $string . ($is_in_val ? ', ' : '') . $value; $string = ''; $is_in_val = false; if ($vals[$i][0] !== "'") { $vals[$i] = "''" . $vals[$i]; } $i++; continue; } else { $string .= ($is_in_val ? ', ' : '') . $value; $is_in_val = true; } } if ($string) { // New value if cols != value $vals[sizeof($cols) !== sizeof($vals) ? $i : $i - 1] .= $string; } $vals = array(0 => $vals); } $inserts = $vals[0]; unset($vals); foreach ($inserts as $key => $value) { if (!empty($value) && $value[0] === "'" && strlen($value) > 4002) { $inserts[$key] = ':' . strtoupper($cols[$key]); $array[$inserts[$key]] = str_replace("''", "'", substr($value, 1, -1)); } } $query = $regs[1] . '(' . $regs[2] . ') VALUES (' . implode(', ', $inserts) . ')'; } } else { if (preg_match_all('/^(UPDATE [\\w_]++\\s+SET )([\\w_]++\\s*=\\s*(?:\'(?:[^\']++|\'\')*+\'|[\\d-.]+)(?:,\\s*[\\w_]++\\s*=\\s*(?:\'(?:[^\']++|\'\')*+\'|[\\d-.]+))*+)\\s+(WHERE.*)$/s', $query, $data, PREG_SET_ORDER)) { if (strlen($data[0][2]) > 4000) { $update = $data[0][1]; $where = $data[0][3]; preg_match_all('/([\\w_]++)\\s*=\\s*(\'(?:[^\']++|\'\')*+\'|[\\d-.]++)/', $data[0][2], $temp, PREG_SET_ORDER); unset($data); $cols = array(); foreach ($temp as $value) { if (!empty($value[2]) && $value[2][0] === "'" && strlen($value[2]) > 4002) { $cols[] = $value[1] . '=:' . strtoupper($value[1]); $array[$value[1]] = str_replace("''", "'", substr($value[2], 1, -1)); } else { $cols[] = $value[1] . '=' . $value[2]; } } $query = $update . implode(', ', $cols) . ' ' . $where; unset($cols); } } } } switch (substr($query, 0, 6)) { case 'DELETE': if (preg_match('/^(DELETE FROM [\\w_]++ WHERE)((?:\\s*(?:AND|OR)?\\s*[\\w_]+\\s*(?:(?:=|<>)\\s*(?>\'(?>[^\']++|\'\')*+\'|[\\d-.]+)|(?:NOT )?IN\\s*\\((?>\'(?>[^\']++|\'\')*+\',? ?|[\\d-.]+,? ?)*+\\)))*+)$/', $query, $regs)) { $query = $regs[1] . $this->_rewrite_where($regs[2]); unset($regs); } break; case 'UPDATE': if (preg_match('/^(UPDATE [\\w_]++\\s+SET [\\w_]+\\s*=\\s*(?:\'(?:[^\']++|\'\')*+\'|[\\d-.]++|:\\w++)(?:, [\\w_]+\\s*=\\s*(?:\'(?:[^\']++|\'\')*+\'|[\\d-.]++|:\\w++))*+\\s+WHERE)(.*)$/s', $query, $regs)) { $query = $regs[1] . $this->_rewrite_where($regs[2]); unset($regs); } break; case 'SELECT': $query = preg_replace_callback('/([\\w_.]++)\\s*(?:(=|<>)\\s*(?>\'(?>[^\']++|\'\')*+\'|[\\d-.]++|([\\w_.]++))|(?:NOT )?IN\\s*\\((?>\'(?>[^\']++|\'\')*+\',? ?|[\\d-.]++,? ?)*+\\))/', array($this, '_rewrite_col_compare'), $query); break; } $this->query_result = @ociparse($this->db_connect_id, $query); foreach ($array as $key => $value) { @ocibindbyname($this->query_result, $key, $array[$key], -1); } $success = @ociexecute($this->query_result, OCI_DEFAULT); if (!$success) { $this->sql_error($query); $this->query_result = false; } else { if (!$in_transaction) { $this->sql_transaction('commit'); } } if (defined('DEBUG_EXTRA')) { $this->sql_report('stop', $query); } if ($cache_ttl && method_exists($cache, 'sql_save')) { $this->open_queries[(int) $this->query_result] = $this->query_result; $cache->sql_save($query, $this->query_result, $cache_ttl); } else { if (strpos($query, 'SELECT') === 0 && $this->query_result) { $this->open_queries[(int) $this->query_result] = $this->query_result; } } } else { if (defined('DEBUG_EXTRA')) { $this->sql_report('fromcache', $query); } } } else { return false; } return $this->query_result; }
// bind procedure parameters $ret = ociexecute($mycursor); // Execute function $ret = ociexecute($outrefc); // Execute cursor $nrows = ocifetchstatement($outrefc, $pos1); // fetch data from cursor ocifreestatement($mycursor); // close procedure call ocifreestatement($outrefc); // 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];
/** * Bind parameters * * @access private * @return none */ function _bind_params($params) { if (!is_array($params) or !is_resource($this->stmt_id)) { return; } foreach ($params as $param) { foreach (array('name', 'value', 'type', 'length') as $val) { if (!isset($param[$val])) { $param[$val] = ''; } } ocibindbyname($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']); } }
/** * 分页算法从 adodb 修改 */ function selectLimit($sql, $length = 'ALL', $offset = 0) { if (strpos($sql, '/*+') !== false) { $sql = str_replace('/*+ ', '/*+FIRST_ROWS ', $sql); } else { $sql = preg_replace('/^[ \\t\\n]*SELECT/i', 'SELECT /*+FIRST_ROWS*/', $sql); } $selectOffsetAlg1 = 100; $inputarr = array(); if ($offset < $selectOffsetAlg1) { if ($length > 0) { if ($offset > 0) { $length += $offset; } $sql = "SELECT * FROM ({$sql}) WHERE ROWNUM <= :length"; $inputarr['length'] = $length; } $stmt = $this->execute($sql, $inputarr); for ($i = 0; $i < $offset; $i++) { ocifetch($stmt); } return $stmt; } else { // Algorithm by Tomas V V Cox, from PEAR DB oci8.php // Let Oracle return the name of the columns $qfields = "SELECT * FROM ({$sql}) WHERE NULL = NULL"; $stmt = ociparse($this->conn, $qfields); if (!$stmt) { return false; } if (is_array($inputarr)) { foreach (array_keys($inputarr) as $k) { ocibindbyname($stmt, $k, $inputarr[$k], -1); } } if (!ociexecute($stmt, OCI_DEFAULT)) { ocifreestatement($stmt); return false; } $ncols = ocinumcols($stmt); for ($i = 1; $i <= $ncols; $i++) { $cols[] = '"' . ocicolumnname($stmt, $i) . '"'; } ocifreestatement($stmt); $fields = implode(', ', $cols); $length += $offset; $offset += 1; // in Oracle rownum starts at 1 $sql = "SELECT {$fields} FROM " . "(SELECT rownum as adodb_rownum, {$fields} FROM " . "({$sql})" . ' WHERE rownum <= :adodb_nrows) WHERE adodb_rownum >= :adodb_offset'; $inputarr['adodb_nrows'] = $length; $inputarr['adodb_offset'] = $offset; return $this->execute($sql, $inputarr); } }
OCIdefinebyname($stmt00, "cheqcontr", $cheqcontr, 10); OCIdefinebyname($stmt00, "cheqfam", $cheqfam, 6); OCIdefinebyname($stmt00, "cheqtpus", $cheqtpus, 2); OCIdefinebyname($stmt00, "aoachou_cheque", $aoachou_cheque, 1); OCIexecute($stmt00); if (OCIFetch($stmt00)) { $aocheque_utilizado = OCIResult($stmt00, 1); $cheqcontr = OCIResult($stmt00, 2); $cheqfam = OCIResult($stmt00, 3); $cheqtpus = OCIResult($stmt00, 4); $aoachou_cheque = OCIResult($stmt00, 5); } OCIFreeStatement($stmt00); if ($aoachou_cheque != '1') { $stmt55 = ociparse($conn, "\n begin :sit1 := F_VALIDA_PRE_AUTORIZACAO('{$nrcheq}',\n NULL ,\n NULL ,\n '{$contrato}',\n '{$familiag}',\n '{$dependencia}',\n '{$data2}' ,\n '{$sv}',\n 'CORRETO' ,\n 'N' ); END;"); ocibindbyname($stmt55, "sit1", $sit1, 120); ociexecute($stmt55); OCIFreeStatement($stmt55); if ($sit1 != 'CORRETO') { $erro = 'S'; OCILogoff($conn); print "<SCRIPT LANGUAGE=JAVASCRIPT>\n alert('{$sit1}');\n window.location.replace('cheqc.php');\n </SCRIPT>"; } } else { if ($aocheque_utilizado != !1) { $erro = 'S'; OCILogoff($conn); print "<SCRIPT LANGUAGE=JAVASCRIPT>alert('O Cheque Consulta {$nrcheq} já foi utilizado');window.location.replace('blank2.htm');</SCRIPT>"; } if ($aoutiliza_cheque_consulta == 'F') { if ($cheqcontr != $contrato or $cheqfam != $familiag) {
function _initialize() { header("Expires: " . date('r', strtotime('+ 30 min'))); $conn_db = _ocilogon($this->db); //剩下没解决的 $sql = "select sum(t.fun_count) c from {$this->report_monitor_date} t where t.v1 like '%(项目满意分)' and t.cal_date = trunc(sysdate)"; $stmt = _ociparse($conn_db, $sql); _ociexecute($stmt); $_row = array(); ocifetchinto($stmt, $_row, OCI_ASSOC + OCI_RETURN_LOBS + OCI_RETURN_NULLS); $_row['C'] = sprintf('%02d', $_row['C']); $sql = "select sum(t.fun_count) c from {$this->report_monitor_date} t where t.v1 like '%(项目文档满意分)' and t.cal_date = trunc(sysdate)"; $stmt = _ociparse($conn_db, $sql); _ociexecute($stmt); $_row2 = array(); ocifetchinto($stmt, $_row2, OCI_ASSOC + OCI_RETURN_LOBS + OCI_RETURN_NULLS); $_row2['C'] = sprintf('%02d', $_row2['C']); if ($_row['C']) { echo "\$('#nbi_num_xm').html('文档:{$_row2['C']}分');\$('#nbi_num_1').html('技术:{$_row['C']}分');"; } //显示其他定制的分数 $sql = "select * from {$this->report_monitor_v1} t where t.PINFEN_RULE_NAME is not null "; $stmt_list = _ociparse($conn_db, $sql); _ociexecute($stmt_list); $_row = $_row2 = array(); $ki = 1; while (ocifetchinto($stmt_list, $_row2, OCI_ASSOC + OCI_RETURN_LOBS + OCI_RETURN_NULLS)) { $_row = unserialize($_row2['PINFEN_RULE']); if ($_row2['PINFEN_RULE_NAME'] && $_row['pinfen_name'] && $_row['koufen_name'] && $_row['base_num'] && $_row['just_rule'] && $_row['pinfen_step'] && $_row['rule_num']) { $ki++; $sql = "select sum(t.fun_count) c from {$this->report_monitor_date} t where t.v1 =:v1 and t.cal_date = trunc(sysdate)"; $stmt = _ociparse($conn_db, $sql); ocibindbyname($stmt, ':v1', $_row['pinfen_name']); _ociexecute($stmt); $_row3 = array(); ocifetchinto($stmt, $_row3, OCI_ASSOC + OCI_RETURN_LOBS + OCI_RETURN_NULLS); $_row3['C'] = sprintf('%02d', $_row3['C']); echo "try{\$('#nbi_num_{$ki}').html('{$_row2['PINFEN_RULE_NAME']}:{$_row3['C']}分');}catch(e){}"; } } //总pv量 $all_num = 0; $sql = "select * from {$this->report_monitor_config} t where v1 like '%(WEB日志分析)' and v2<>'汇总'"; $stmt = _ociparse($conn_db, $sql); _ociexecute($stmt); $this->host = $_row = array(); while (ocifetchinto($stmt, $_row, OCI_ASSOC + OCI_RETURN_LOBS + OCI_RETURN_NULLS)) { $_row['V2_CONFIG_OTHER'] = unserialize($_row['V2_CONFIG_OTHER']); $this->host[$_row['V2']] = $_row; } $s1 = date('Y-m-d'); $sql = "select t.*,to_char(cal_date, 'yyyy-mm-dd') CAL_DATE_F from\n {$this->report_monitor_date} t where\n cal_date>=to_date(:s1,'yyyy-mm-dd') and v1 like '%(WEB日志分析)' and v2<>'汇总' "; $stmt = _ociparse($conn_db, $sql); _ocibindbyname($stmt, ':s1', $s1); $oci_error = _ociexecute($stmt); while (ocifetchinto($stmt, $_row, OCI_ASSOC + OCI_RETURN_LOBS + OCI_RETURN_NULLS)) { if (!$this->host[$_row['V2']]['V2_CONFIG_OTHER']['NO_COUNT']) { $all_num += $_row['FUN_COUNT']; } } if ($all_num > 10000 * 10000) { $all_num = round($all_num / 10000 / 10000, 1) . '亿'; } elseif ($all_num > 10000) { $all_num = round($all_num / 10000, 1) . '万'; } echo "\$('#nbi_num_pv').html('pv:{$all_num}');"; }
public function eliminarUsuario($cedula, $codigo) { $this->conex = DataBase::getInstance(); $stid = oci_parse($this->conex, "UPDATE FISC_USERS SET INT_BORRADO = 1 WHERE ID_USER =:cedula"); if (!$stid) { $e = oci_error($this->conex); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); return false; } ocibindbyname($stid, ':cedula', $cedula); $r = oci_execute($stid, OCI_NO_AUTO_COMMIT); if (!$r) { $e = oci_error($stid); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); return false; } /*INSERTANDO EN TBL_GESTION_USUARIOS*/ $consulta_gestion = "INSERT INTO TBL_GESTION_USUARIOS(\n\t\tCODIGO_USUARIO,\n\t\tACCION,\n\t\tFECHA,\n\t\tDESCRIPCION,\n\t\tRESPONSABLE)\nvalues \n(\n\t:codigo_usuario,\n\t:accion,\n\t:fecha,\n\t:descripcion,\n\t:responsable\n\t)"; $responsable = $_SESSION['USUARIO']['codigo_usuario']; $accion = 3; $fecha = date('d/m/y'); $descripcion = "Eliminar usuario"; $stid_gestion = oci_parse($this->conex, $consulta_gestion); if (!$stid_gestion) { $e = oci_error($this->conex); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); //$e = oci_error($this->conex); //trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); //Libera los recursos oci_free_statement($stid); oci_free_statement($stid_gestion); // Cierra la conexión Oracle oci_close($this->conex); return false; } // Realizar la lógica de la consulta oci_bind_by_name($stid_gestion, ':codigo_usuario', $codigo); oci_bind_by_name($stid_gestion, ':accion', $accion); oci_bind_by_name($stid_gestion, ':fecha', $fecha); oci_bind_by_name($stid_gestion, ':descripcion', $descripcion); oci_bind_by_name($stid_gestion, ':responsable', $responsable); $result_gestion = oci_execute($stid_gestion, OCI_NO_AUTO_COMMIT); if (!$result_gestion) { echo "Desde el execute 2"; $e = oci_error($this->conex); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); //Revertimos los cambios oci_rollback($this->conex); //Libera los recursos oci_free_statement($stid_gestion); oci_free_statement($stid); // Cierra la conexión Oracle oci_close($this->conex); return false; } /*INSERTANDO EN TBL_GESTION_USUARIOS*/ $result = oci_commit($this->conex); if (!$result) { oci_close($this->conex); return false; } oci_free_statement($stid); oci_close($this->conex); return true; }
function buscarUsuario($cedula) { //Abrir la conexión $conex = DataBase::getInstance(); $stid = oci_parse($conex, "SELECT * FROM FISC_USERS WHERE ID_USER=:cedula"); if (!$stid) { $e = oci_error($conex); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } // Realizar la lógica de la consulta ocibindbyname($stid, ':cedula', $cedula); $r = oci_execute($stid); if (!$r) { $e = oci_error($stid); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } // Obtener los resultados de la consulta $fila = oci_fetch_array($stid, OCI_ASSOC + OCI_RETURN_NULLS); //Libera los recursos oci_free_statement($stid); // Cierra la conexión Oracle oci_close($conex); return array($fila, count($stid)); }
/** * @desc WHAT? * @author * @since 2012-11-25 17:33:09 * @throws 注意:无DB异常处理 */ function _ocibindbyname($stmt, $key, $value) { settype($_SERVER['last_oci_bindname'], 'Array'); $_SERVER['last_oci_bindname'][$key] = $value; ocibindbyname($stmt, $key, $value); }
session_is_registered(); set_magic_quotes_runtime(); set_socket_blocking(); split(); spliti(); sql_regcase(); php_logo_guid(); php_egg_logo_guid(); php_real_logo_guid(); zend_logo_guid(); datefmt_set_timezone_id(); mcrypt_ecb(); mcrypt_cbc(); mcrypt_cfb(); mcrypt_ofb(); ocibindbyname(); ocicancel(); ocicloselob(); ocicollappend(); ocicollassign(); ocicollassignelem(); ocicollgetelem(); ocicollmax(); ocicollsize(); ocicolltrim(); ocicolumnisnull(); ocicolumnname(); ocicolumnprecision(); ocicolumnscale(); ocicolumnsize(); ocicolumntype();