我需要在 Laravel 数据库中编写一个原始查询:查询生成器,输出特定表的大小
mysql核心查询如下
SELECT table_name "Name_of_the_table", table_rows "Rows Count", round(((data_length + index_length)/1024/1024),2)
"Table Size (MB)" FROM information_schema.TABLES WHERE table_schema = "Name_of_the_Database" AND table_name ="Name_of_the_table";
最佳答案
您可以在 laravel 中使用原始查询来获取记录,例如:
$sql = 'SELECT table_name "Name_of_the_table", table_rows "Rows Count", round(((data_length + index_length)/1024/1024),2)
"Table Size (MB)" FROM information_schema.TABLES WHERE table_schema = "Name_of_the_Database" AND table_name ="Name_of_the_table"';
$results = DB::select($sql);
关于mysql - 如何在 Laravel 中编写原始查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54780822/