yii中如何判断数据表是否存在于数据库中

yii中如何判断数据表是否存在于数据库中

判断方法分为两步:

第一步:找出数据库中所有表名,表名得到的是二维数组。

第二步:判断表名是否存在二维数组中。

代码示例:

$table_name =‘table’;         $juge = $handle->createCommand("show tables ")->queryAll(); //下面的deep_in_array()方法是自己写的方法,判断是否存在值是否存在二维数组中,yii2中调用本类方法,可以去掉action         $cun =  $this->deep_in_array($table_name,$juge);           if(!$cun){               echo json_encode("nodata");               return;           }
//判断二维数组是否存在值     public  function deep_in_array($value, $array) {                foreach($array as $item) {                    if(!is_array($item)) {                        if ($item == $value) {                           return true;                       } else {                           continue;                        }                   }                                        if(in_array($value, $item)) {                       return true;                       } else if($this->deep_in_array($value, $item)) {                       return true;                       }               }                return false;            }

相关文章教程推荐:yii教程

© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享