源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

php检测mysql表是否存在的方法小结

  • 时间:2021-11-06 01:34 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:php检测mysql表是否存在的方法小结
本文实例讲述了php检测mysql表是否存在的方法。分享给大家供大家参考,具体如下: [b]pdo:[/b]
<?php
$dsn = 'mysql:dbname=test;host=127.0.0.1';
$user = 'root';
$password = '';
try {
  $pdo = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
  die("数据库连接失败".$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";
}
?>

[b]mysql:[/b]
<?php
$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";
}
?>

更多关于PHP相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/192.htm]PHP基于pdo操作数据库技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/759.htm]php+Oracle数据库程序设计技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/586.htm]PHP+MongoDB数据库操作技巧大全[/url]》、《[url=http://www.1sucai.cn/Special/43.htm]php面向对象程序设计入门教程[/url]》、《[url=http://www.1sucai.cn/Special/47.htm]php字符串(string)用法总结[/url]》、《[url=http://www.1sucai.cn/Special/84.htm]php+mysql数据库操作入门教程[/url]》及《[url=http://www.1sucai.cn/Special/231.htm]php常见数据库操作技巧汇总[/url]》 希望本文所述对大家PHP程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部