It is divided into two steps: (Recommended learning: yii tutorial)
The first step is to find out the All table names are obtained as two-dimensional arrays.
The second step is to determine whether the table name exists in the two-dimensional array
I will post my code below.
$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; }
The above is the detailed content of yii2 determines whether the table exists. For more information, please follow other related articles on the PHP Chinese website!