php检测数据库表 php怎么判断数据库是否有某个数据

如何用php判断mysql数据库里某张表是否存在?php
/*
查询数据库是否存在功能
$sql:查询数据库php检测数据库表的SQL语句
$find_table:需要检查php检测数据库表的表名
*/
mysql_connect('localhost','root','2260375') or die('can\'t not connect database');
if((int)check_table_is_exist('show databases;','test')==1)
{
echo '该表存在';
【php检测数据库表 php怎么判断数据库是否有某个数据】}
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;
}
}
?
php中检测某mysql数据库是否存在?php
$lnk = mysql_connect('localhost', 'mysql_user', 'mysql_password')
or die ('Not connected : ' . mysql_error());
// make foo the current db
mysql_select_db('foo', $lnk) or die ('Can\'t use foo : ' . mysql_error());
?
PHP 如何查看数据库中数据表是否存在可以用下面的代码查看数据库中数据表是否存在:
$con = mysql_connect("localhost","$username","$password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("$datebase_name", $con);
$result = mysql_query("SELECT * FROM your_table");
while($row = mysql_fetch_array($result))
{if(!$row){echo "表不存在!";}else{echo "表存在!";}
}
mysql_close($con);
php检测数据库表的介绍就聊到这里吧,感谢你花时间阅读本站内容 , 更多关于php怎么判断数据库是否有某个数据、php检测数据库表的信息别忘了在本站进行查找喔 。

    推荐阅读