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.
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!