Home PHP Framework YII How to determine whether the data table exists in the database in Yii

How to determine whether the data table exists in the database in Yii

Dec 17, 2019 pm 05:10 PM
yii judgment database data sheet

How to determine whether the data table exists in the database in Yii

The 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;
          }
Copy after login
//判断二维数组是否存在值
    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;   
        }
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How does Go language implement the addition, deletion, modification and query operations of the database? How does Go language implement the addition, deletion, modification and query operations of the database? Mar 27, 2024 pm 09:39 PM

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 Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

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 iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

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

How does Hibernate implement polymorphic mapping? How does Hibernate implement polymorphic mapping? Apr 17, 2024 pm 12:09 PM

How does Hibernate implement polymorphic mapping?

How to determine whether a date is the previous day in Go language? How to determine whether a date is the previous day in Go language? Mar 24, 2024 am 10:09 AM

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

An in-depth analysis of how HTML reads the database An in-depth analysis of how HTML reads the database Apr 09, 2024 pm 12:36 PM

An in-depth analysis of how HTML reads the database

Analysis of the basic principles of MySQL database management system Analysis of the basic principles of MySQL database management system Mar 25, 2024 pm 12:42 PM

Analysis of the basic principles of MySQL database management system

How does Go WebSocket integrate with databases? How does Go WebSocket integrate with databases? Jun 05, 2024 pm 03:18 PM

How does Go WebSocket integrate with databases?

See all articles