<?php
$handle=@mysql_connect("localhost","root","");
if (!$handle)
{
die("No connection to database");
}
echo 'Total number of all-time mysql-queries: '.getTotalNumberOfMySQLQuerys();
//Returns integer-value of the total number of alltime mysql-calls that have been made
function getTotalNumberOfMySQLQuerys()
{
//global mysql-status containing the number of querys has been renamed in newer versions of mysql
$mysqlVersion=getMysqlVersion();
//contact helper-function to receive the mysql-version
if ($mysqlVersion()>=50002)
{
$sql="SHOW GLOBAL STATUS LIKE 'Questions'";
}
else
{
$sql="SHOW STATUS LIKE 'Questions'";
}
$result=@mysql_query( $sql );
$row=@mysql_fetch_array( $result );
return $row['Value'];
}
//helper function is needed to detect the exact mysql-version
function getMysqlVersion()
{
$sql = 'SELECT VERSION() AS versionsinfo';
$result = @mysql_query('SELECT VERSION() AS versionsinfo');
$version = @mysql_result( $result, 0, "versionsinfo" );
$match = explode('.',$version);
return sprintf('%d%02d%02d',$match[0],$match[1],intval($match[2]));
}
?>
由于包含查询次数的全局 mysql-status-变量的名称在更高版本的 mysql 中发生了变化,因此需要一个辅助函数来检测您正在运行的 mysql 的确切版本。
看起来不错,但是
$conn 应该为 $handle。
mysqlVersion()>=50002
应该改为
$mysqlVersion>=50002
然后它就可以正常工作了。
在我的一个相当小的网站上,这个数字是 77352281。太可怕了!
感谢您的修正!
Rich 的修复确实有效,有没有办法更改原始错误?我复制粘贴了代码,不得不自己找到那个错误,然后才想到查看评论。如果可以在原始教程中更改它,可以为其他人节省更多时间。
嘿,这很酷,谢谢。不过,它仍然需要一些修改才能工作,不过,只要对 PHP 有基本的了解,这应该不是问题。