This article is mainly to share with you PHPL Judge mysq database data table exists, there are two main ways, hope to help everyone.
Note: The following are all tested in the thinkphp framework
Mode 1
By querying the configuration table information for MySQL
Table_schema: Represents the database name, TABLE_NAME: Represents the table name $sql = "SELECT count (*) from INFORMATION_SCHEMA. TABLES WHERE table_schema= ' database_name ' and table_name = ' table_name '; $model = new \think\model (); $res = $model->query ($sql); $isExist = $res [0];
Mode 2
Queries all data tables in the specified data, and then compares the queried data tables for existence
Detects if the table exists function tableexist ($tableName) { if (empty ($tableName)) return false; $tableName = C (' Db_prefix '). $tableName; $model = new \think\model (); $TABLEARR = $model->query (' SHOW TABLES '); $_fname = ' Tables_in_ '. C (' db_name '); Return In_array ($tableName, Array_column ($TABLEARR, $_fname));}