发一个获取mysql数据库版本和数据库大小类
发布于:2022-01-17 09:50:54
#1 拓文
项目开发要获取mysql数据库版本和数据库大小,spModel没有这两个方法,只能自己做了。
class dbinfo extends spModel
{
public function getversion(){//获得mysql数据库版本
$version = $this->findSql("select version() as ver");
return $version[0]['ver'];
}
public function getdbsize(){//获得数据库大小
$sql = "SHOW TABLE STATUS FROM ".$GLOBALS['G_SP']['db']['database'];
if($tblPrefix != null) {
$sql .= " LIKE '{$GLOBALS['G_SP']['db']['prefix']}'";
}
$row = $this->findSql($sql);
$size = 0;
foreach($row as $value) {
$size += $value["Data_length"] + $value["Index_length"];
}
return round($size/1048576).'M';
}
}
2011-11-30 01:27:21
#2 拓文
晕,不支持编辑功能的?
去掉
if($tblPrefix != null) {
$sql .= " LIKE '{$GLOBALS['G_SP']['db']['prefix']}'";
}
2011-11-30 01:32:51
#3 拓文
修改了一下
class dbinfo extends spModel
{
public function getversion(){//获得mysql数据库版本
$version = $this->findSql("select version() as ver");
return $version[0]['ver'];
}
public function getdbsize(){//获得数据库大小
$sql = "SHOW TABLE STATUS FROM ".$GLOBALS['G_SP']['db']['database'];
$tblPrefix = $GLOBALS['G_SP']['db']['prefix'];
if($tblPrefix != null) {
$sql .= " LIKE '{$tblPrefix}%'";
}
$row = $this->findSql($sql);
$size = 0;
foreach($row as $value) {
$size += $value["Data_length"] + $value["Index_length"];
}
return round($size/1048576).'M';
}
}
2011-11-30 01:42:45
#4 jake
:handshake 很好
2011-11-30 07:30:31
#5 yi210
{:soso__3409329614010722382_3:}
2013-05-25 11:31:24