yizh

$query = mysqli_query($link,"explain $sql")出错, 如何修改

public function query($sql, $link = NULL, $isthrow = TRUE) {

empty($link) && $link = $this->wlink;


if(defined('DEBUG') && DEBUG && isset($_ENV['_sqls']) && count($_ENV['_sqls']) < 1000) {

$start = microtime(1);

$result = mysqli_query($link, $sql);  //$result = mysql_query($sql, $link);

$runtime = number_format(microtime(1) - $start, 4);


// explain 分析 select 语句

$explain_str = '';

if(substr($sql, 0, 6) == 'SELECT') {

     //echo  $sql; //测试

$query = mysqli_query($link,"explain $sql"); //$query = mysql_query("explain $sql", $link);

if($query !== FALSE) {

$explain_arr = mysqli_fetch_assoc($query);  //$explain_arr = mysql_fetch_assoc($query);

//print_r($explain_arr);

$explain_str = ' <font color="blue">[explain type: '.$explain_arr['type'].' | rows: '.$explain_arr['rows'].']</font>';

}

}

$_ENV['_sqls'][] = ' <font color="red">[time:'.$runtime.'s]</font> '.htmlspecialchars(stripslashes($sql)).$explain_str;

}else{

$result = mysqli_query($link, $sql);  //$result = mysql_query($sql, $link);

}


if(!$result && $isthrow) {

$s = 'MySQL Query Error: <b>'.$sql.'</b>. '.mysql_error();


if(defined('DEBUG') && !DEBUG) $s = str_replace($this->tablepre, '***', $s); // 防止泄露敏感信息


throw new Exception($s);

}

$_ENV['_sqlnum']++;

return $result;

}

#1楼
发帖时间:2018-5-1   |   查看数:0   |   回复数:0
游客组