检查表是否存在,然后不包括php

时间:2017-02-21 21:15:57

标签: php sql

如果我的数据库中存在名称与$ current_product_name相同的表,是否可以包含php文件。这是我已经连接到数据库的代码。

<?php
$sql = "SELECT * FROM $current_product_name";
$result = $conn->query($sql);
if ($result = $mysqli->query("SHOW TABLES LIKE '".$current_product_name."'"))
{
 if($result->num_rows == 1) { include_once("getProduct.php");}
 }
 else { echo "Product not available."; }
 ?>

1 个答案:

答案 0 :(得分:0)

容易。 查询数据库以查看表是否存在。如果是的话,你会得到真实的回报。如果是,则包含该内容。