欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

TP获得mysql版本及mysql数据库大小

程序员文章站 2022-04-30 11:52:58
...
TP获得mysql版本及mysql数据库大小
namespace Admin\Controller;
use Think\Controller;
class SystemController extends AdminController
{
protected function _model(){
return new \Think\Model();
}

public function indexAction()
{
layout( true );
$this->sysinfo = array(
'os' => $_SERVER["SERVER_SOFTWARE"], //获取服务器标识的字串
'version' => PHP_VERSION, //获取PHP服务器版本
'time' => date("Y-m-d H:i:s", time()), //获取服务器时间
'pc' => $_SERVER['SERVER_NAME'], //当前主机名
'osname' => php_uname(), //获取系统类型及版本号
'language' => $_SERVER['HTTP_ACCEPT_LANGUAGE'], //获取服务器语言
'port' => $_SERVER['SERVER_PORT'], //获取服务器Web端口
'max_upload' => ini_get("file_uploads") ? ini_get("upload_max_filesize") : "Disabled", //最大上传
'max_ex_time' => ini_get("max_execution_time")."秒", //脚本最大执行时间
'mysql_version' => $this->_mysql_version(),
'mysql_size' => $this->_mysql_db_size(),
);
$this->display();
}

private function _mysql_version()
{
$Model = self::_model();
$version = $Model->query("select version() as ver");
return $version[0]['ver'];
}

private function _mysql_db_size()
{
$Model = self::_model();
$sql = "SHOW TABLE STATUS FROM ".C('DB_NAME');
$tblPrefix = C('DB_PREFIX');
if($tblPrefix != null) {
$sql .= " LIKE '{$tblPrefix}%'";
}
$row = $Model->query($sql);
$size = 0;
foreach($row as $value) {
$size += $value["Data_length"] + $value["Index_length"];
}
return round(($size/1048576),2).'M';
}
}
不足之处望指点!http://www.yi210.com/archives/919.html

AD:真正免费,域名+虚机+企业邮箱=0元