您的位置:首页 > 数据库

判断数据库中数据表是否存在

2016-05-10 00:29 615 查看
<?php
/**
* 查询数据库是否存在功能    $sql:查询数据库的SQL语句        $find_table:需要检查的表名
*/

mysql_connect('localhost', 'root', '2260375') or die('can\'t not connect database');
if ((int)check_table_is_exist('show databases;', 'test') == 1) {
echo '该表存在';
} else {
echo '该表不存在';
}
function check_table_is_exist($sql, $find_table) {
$row = mysql_query($sql);
$database = array();
$finddatabase = $find_table;
while ($result = mysql_fetch_array($row, MYSQL_ASSOC)) {
$database[] = $result['Database'];
}
unset($result, $row);
mysql_close();
/**
* 开始判断表是否存在
*/ if (in_array($find_table, $database)) {
return true;
} else {
return false;
}
}

?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: