ThinkPHP怎么查询数据库所有的表名呢?

业务场景:有一些数据库中的表示随机生成有规则的表

比如:server1、server2……

见下面:

没有看到教程上有写 show tables的写法 ,所以就用了原生的:


    //获取所有的表名
    public function getTables(){
        //获取表名
       $result = self::query('show tables');

       if(!empty($result)){
       //   将表名转换为大写
           $ChineseTable = array();
           $commonController  = new \app\common\controller\Common();
           $i = 0;
           foreach ($result as $value){
             $num = (int)substr($value['Tables_in_pai_test'],16);
             $commonResult = $commonController->numberToChinese($num);
             $ChineseTable[$i] = '服务器'.$commonResult;
             $i ++;
           }

           return $ChineseTable;

       }
    }

然后想要拿到对应数据表中的数据,根据表名去查就ok了

猜你喜欢

转载自blog.csdn.net/wqzbxh/article/details/83141940
今日推荐