php mysql 值是否存在_php检测mysql表是否存在的方法小结
本文實(shí)例講述了php檢測(cè)mysql表是否存在的方法。分享給大家供大家參考,具體如下:
pdo:
$dsn = 'mysql:dbname=test;host=127.0.0.1';
$user = 'root';
$password = '';
try {
$pdo = new pdo($dsn, $user, $password);
} catch (pdoexception $e) {
die("數(shù)據(jù)庫(kù)連接失敗".$e->getmessage());
}
$table = 'cy_news';
//判斷表是否存在
$result = $pdo->query("show tables like '". $table."'");
$row = $result->fetchall();
if('1' == count($row)){
echo "table exists";
} else {
echo "table does not exist";
}
?>
mysql:
$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";
}
?>
希望本文所述對(duì)大家php程序設(shè)計(jì)有所幫助。
希望與廣大網(wǎng)友互動(dòng)??
點(diǎn)此進(jìn)行留言吧!
總結(jié)
以上是生活随笔為你收集整理的php mysql 值是否存在_php检测mysql表是否存在的方法小结的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 其他应收款包括什么(其他应收款包括哪些内
- 下一篇: linux cmake编译源码,linu