如何使用yii2框架检查特定表格是否存在于数据库中?

2026-05-06 21:422阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计184个文字,预计阅读时间需要1分钟。

如何使用yii2框架检查特定表格是否存在于数据库中?

相关主题

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

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

 下面就贴我的代码咯。

$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; }

标签:YII2

本文共计184个文字,预计阅读时间需要1分钟。

如何使用yii2框架检查特定表格是否存在于数据库中?

相关主题

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

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

 下面就贴我的代码咯。

$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; }

标签:YII2