I am trying to embed a function on the site that controls the sql queries and the time spent on them. Naryl in the internet is an interesting solution. Work works, but it produces a 1 sql query all the time. I feel that the dog is buried in the line $ sql_time + = do_query ("SELECT * FROM SOME_TABLE"); but nothing works. Tell me, please, what's the matter?
//Засекаем время старта $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $tstart = $mtime; //Коннектимся к базе: include 'connect.php'; //Объявляем переменные $result=0; $qnum=0; //Объявляем нашу функцию function do_query($query){ global $result; global $qnum; $qnum++; $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $tstart = $mtime; $result = MYSQL_QUERY($query); $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $tend = $mtime; $tpassed = ($tend - $tstart); return($tpassed); } //Далее тело скрипта $sql_time+=do_query("SELECT * FROM SOME_TABLE"); //Обрабатываем данные while($row = mysql_fetch_array($result)){ print($row['Text']); } //Засекаем время окончания $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $tend = $mtime; $total = ($tend - $tstart); //Выдаем время: printf("SQL запросов: $qnum, время mysql: %f, всего затрачено: %f секунд !", $sql_time, $total); //Вычисляем процент времени: $sqlpercent = ($sql_time*100)/$total; print('Процент времени на MySQL: '. round($sqlpercent, 2) . '%');