推断要领分为两步:
第一步:找出数据库中所有表名,表名获得的是二维数组。
第二步:推断表名是不是存在二维数组中。
代码示例:
$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教程
以上就是yii中怎样推断数据表是不是存在于数据库中的细致内容,更多请关注ki4网别的相干文章!