How to determine whether the data table exists in the database in Yii
Dec 17, 2019 pm 05:10 PMThe judgment method is divided into two steps:
The first step: Find all the table names in the database. The table names are obtained as two-dimensional arrays.
Step 2: Determine whether the table name exists in the two-dimensional array.
Code example:
$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; }
Recommended related articles and tutorials: yii tutorial
The above is the detailed content of How to determine whether the data table exists in the database in Yii. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How does Go language implement the addition, deletion, modification and query operations of the database?

Detailed tutorial on establishing a database connection using MySQLi in PHP

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos

How does Hibernate implement polymorphic mapping?

How to determine whether a date is the previous day in Go language?

An in-depth analysis of how HTML reads the database

Analysis of the basic principles of MySQL database management system

How does Go WebSocket integrate with databases?
