0
진단 페이지에 실행 시간보고를 추가하려고하는데 페이지 끝에 추가합니다. 나는 데이터베이스 연결 및 쿼리 실행 처리하는 기능이 있습니다내 로컬 변수를 덮어 쓰지 않는 이유는 무엇입니까?
<?php
// get_data.php
function get_data($sql_statement, $sql_bind_variables=array(), $sql_result_type="cursor", $sql_result_cursor=":results_cursor") {
$time_start = microtime(true);
//tie-in to the existing $connection
global $connection;
global $debugging;
if($debugging['show_debugging_ind']){
global $variables;
$variables['debugging_sql']=$sql_statement;
};
//since we have to determine if the sql result is packaged within a cursor multiple times, let's perform the slow text comparison once, and reference the result in multiple places.
$cursor_ind=0;
if ($sql_result_type=="cursor") {
$cursor_ind=1;
}
if ($cursor_ind) {
$returned_cursor = oci_new_cursor($connection);
if (!$returned_cursor) {
$e = oci_error($connection);
trigger_error('
<h2>Could not create new cursor:</h2>
<div class="row-fluid">
<div class="span1">Connection</div>
<div class="span11"><pre>'.$connection.'</pre></div>
</div>
<div class="row-fluid">
<div class="span1">Message</div>
<div class="span11"><pre class="text-error">'.$e['message'],E_USER_ERROR.'</pre></div>
</div>');
}
}
$sql_parsed=oci_parse($connection, $sql_statement);
if (!$sql_parsed) {
$e = oci_error($connection);
trigger_error('
<div id="parse_error" class="clearfix">
<h2>Could not parse statement:</h2>
<div class="row-fluid">
<div class="span1">SQL</div>
<div class="span11"><pre>'.$sql_parsed.'</pre></div>
</div>
<div class="row-fluid">
<div class="span1">Message</div>
<div class="span11"><pre class="text-error">'.$e['message'],E_USER_ERROR.'</pre></div>
</div>
</div>');
}
if ($cursor_ind) {
oci_bind_by_name($sql_parsed, $sql_result_cursor, $returned_cursor, -1, OCI_B_CURSOR);
}
//loop over the array of bind variables
foreach($sql_bind_variables AS $bind_variable_name => $bind_variable_value) {
// echo "<p>processing ".$bind_variable_name.", value=".$sql_bind_variables[$bind_variable_name]."<br />";
// echo "oci_bind_by_name(sql_parsed, ".$bind_variable_name.", ".$sql_bind_variables[$bind_variable_name].");</p>";
oci_bind_by_name($sql_parsed, $bind_variable_name, $sql_bind_variables[$bind_variable_name]);
}
attempt_execute($sql_parsed);
if ($cursor_ind) {
oci_execute($returned_cursor);
oci_fetch_all($returned_cursor, $sql_results, null, null, OCI_FETCHSTATEMENT_BY_ROW);
}
else {
oci_fetch_all($sql_parsed, $sql_results, null, null, OCI_FETCHSTATEMENT_BY_ROW);
}
oci_free_statement($sql_parsed);
if ($cursor_ind) {
oci_free_statement($returned_cursor);
}
return $sql_results;
if($debugging['show_debugging_ind']){
$time_end = microtime(true);
$variables['execution_time']=$time_end-$time_start;
};
}
?>
그래서이 get_data()
기능이 각 쿼리 호출됩니다를하고 $debugging['show_debugging_ind']
비트가 반전되는 경우, 좀 다른 정보를 저장 :
$get_my_cases=get_data('BEGIN pkg_common.get_cases(:results_cursor,p_type => :p_type,P_USER_ID => :P_USER_ID); END;', array(':p_type'=>'INBOX',':P_USER_ID'=>$variables['username']));
if($debugging['show_debugging_ind']){
$debugging['queries']['get_my_cases']['sql']=$variables['debugging_sql'];
$debugging['queries']['get_my_cases']['results']=$get_my_cases;
$debugging['queries']['get_my_cases']['execution_time']=$variables['execution_time'];
};
$get_team_cases=get_data('BEGIN pkg_common.get_cases(:results_cursor, p_type => :p_type, P_USER_ID => :P_USER_ID, P_ASSIGNED_TO_LOC_CD => :P_ASSIGNED_TO_LOC_CD); END;',array(':p_type'=>'INBOX', ':P_USER_ID'=>$variables['username'], ':P_ASSIGNED_TO_LOC_CD'=>$variables['post']));
if($debugging['show_debugging_ind']){
$debugging['queries']['get_team_cases']['sql']=$variables['debugging_sql'];
$debugging['queries']['get_team_cases']['results']=$get_team_cases;
$debugging['queries']['get_team_cases']['execution_time']=$variables['execution_time'];
};
을 내 diagnotics에서는 SQL 텍스트 ($variables['debugging_sql']
)가 업데이트되고 훌륭하게 표시되지만 $variables['execution_time']
시간 변수가 설정되지 않았거나 모든 쿼리에 대해 동일한 값을 얻고 있습니다. 내가 도대체 뭘 잘못하고있는 겁니까?