How to query whether a data table exists in php

王林
Release: 2023-03-05 20:44:01
Original
5384 people have browsed it

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'";
Copy after login

2. Then query execution

$result = mysqli_query($sql) ;
Copy after login

3. Judge based on the result

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

Implementation code:

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

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!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template