新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
yii中判斷數(shù)據(jù)表是否存在于數(shù)據(jù)庫(kù)中的方法-創(chuàng)新互聯(lián)
這篇文章主要介紹yii中判斷數(shù)據(jù)表是否存在于數(shù)據(jù)庫(kù)中的方法,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
判斷方法分為兩步:
第一步:找出數(shù)據(jù)庫(kù)中所有表名,表名得到的是二維數(shù)組。
第二步:判斷表名是否存在二維數(shù)組中。
代碼示例:
$table_name =‘table’; $juge = $handle->createCommand("show tables ")->queryAll(); //下面的deep_in_array()方法是自己寫的方法,判斷是否存在值是否存在二維數(shù)組中,yii2中調(diào)用本類方法,可以去掉action $cun = $this->deep_in_array($table_name,$juge); if(!$cun){ echo json_encode("nodata"); return; }
//判斷二維數(shù)組是否存在值 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中判斷數(shù)據(jù)表是否存在于數(shù)據(jù)庫(kù)中的方法”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
網(wǎng)頁(yè)名稱:yii中判斷數(shù)據(jù)表是否存在于數(shù)據(jù)庫(kù)中的方法-創(chuàng)新互聯(lián)
轉(zhuǎn)載源于:http://www.dlmjj.cn/article/dgjesj.html