查看mysql数据库是否存在某张表及某张表是否存在某个字段

1、通过information_schema查询数据库是否存在某张表

select t.table_name from information_schema.TABLES t where t.TABLE_SCHEMA ='".$database."' and t.TABLE_NAME ='".$table."';
$database:查询的数据库
$table :查询表格

返回:若存在则返回表名,不存在返回为空

 2、判断表中一个字段是否存在

select count(*) from information_schema.columns where table_name = '表名' and column_name = '字段名'

select count(*) from information_schema.columns where table_name = 't_iov_vehicle_owner_info' and column_name = 'id'

原文地址:https://www.cnblogs.com/yaradish/p/10078640.html