判断表是否存在
<?php
//方法一
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;
}
}
//////////////////////////////////////////////方法二
mysql_connect('localhost','root','root');
$result = mysql_list_tables('database');
$i=0;
while($i<mysql_num_rows($result))
{
if ('Table_Name' == mysql_tablename($result,$i)) {
echo '存在';
break;
}
$i++;
}
echo '不存在';
mysql_close();
//////////////////////////////////////方法三
$data = array();
$dbname = '你要查询的表名';
mysql_connect('localhost', 'root', '') or die('Cann\'t connect server!');
$result = mysql_query('show databases;');
While($row = mysql_fetch_assoc($result)){
$data[] = $row['Database'];
}unset($result, $row);
mysql_close();
print_r($data);
if (in_array(strtolower($dbname), $data))
die('存在');
else
die('不存在');
?>以上就是判断表是否存在的内容,更多相关内容请关注PHP中文网(www.php.cn)!
2088shop商城购物系统是商城系统中功能最全的一个版本:非会员购物、商品无限级分类、不限商品数量、商品多级会员定价、上货库存、Word在线编辑器、订单详情销售报表、商品评论、留言簿、管理员多级别、VIP积分、会员注册积分奖励、智能新闻发布、滚动公告、投票调查、背景图片颜色更换、店标上传、版权联系方式修改、背景音乐(好歌不断)、广告图片支持Flash、弹出浮动广告、搜索引擎关健词优化、图文友情联
0
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号