手机
当前位置:查字典教程网 >编程开发 >php教程 >php判断表是否存在的方法
php判断表是否存在的方法
摘要:本文实例讲述了php判断表是否存在的方法。分享给大家供大家参考。具体如下:希望本文所述对大家的php程序设计有所帮助。

本文实例讲述了php判断表是否存在的方法。分享给大家供大家参考。具体如下:

<?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程序设计有所帮助。

【php判断表是否存在的方法】相关文章:

php实现随机显示图片方法汇总

php替换字符串中间字符为省略号的方法

php统计数组元素个数的方法

smarty模板判断数组为空的方法

php将字符串随机分割成不同长度数组的方法

JavaScript实现滚动栏效果的方法

php判断文本文档字符编码

PHP准确取得服务器IP地址的方法

php操作redis缓存方法分享

php跨服务器访问方法小结

精品推荐
分类导航