Home >Backend Development >PHP Problem >How to query whether a data table exists in php

How to query whether a data table exists in php

王林
王林Original
2020-09-11 14:43:085422browse

How to query whether a data table exists in php: first write the sql statement [show tabels like 'table']; then use the mysqli_query() function to execute the sql statement; finally use the empty() function to determine whether the execution result is false. That’s it.

How to query whether a data table exists in php

Solution:

(Related tutorial: php video tutorial)

1. Write A native sql

$sql = "show tabels like 'table'";

2. Then query execution

$result = mysqli_query($sql) ;

3. Judge based on the result

if(!empty($result)){echo "存在";}else{echo "不存在"}

Implementation code:

  $sql = 'SHOW TABLES LIKE "'.$tableName.'"';
  $checkTabel =self::query( $sql);
  if(!empty($checkTabel)){
                try {
                 
                } catch(Exception $e) {
                
                }
            }else{
             
            }

Related recommendations : php training

The above is the detailed content of How to query whether a data table exists in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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