1、在Yii2框架中判断数据表是否存在。
private static function checkTable($table){
$sql = “SHOW TABLES LIKE '”. $table."’";
e
x
i
s
t
T
a
b
l
e
=
s
t
a
t
i
c
:
:
f
i
n
d
B
y
S
q
l
(
existTable = static::findBySql(
existTable=static::findBySql(sql)->asArray()->one();
if(empty($existTable)){
return 0;
}
return 1;
}
2、在php中判断数据表是否存在。
$con = mysql_connect(“localhost”,“root”,"");
mysql_select_db(“php_cms”, $con);
$table = ‘cy_news’;
if(mysql_num_rows(mysql_query(“SHOW TABLES LIKE '”. $table."’"))==1) {
echo “Table exists”;
} else {
echo “Table does not exist”;
}