2017-02-21 59 views
0

如果我的数据库中存在一个名称与$ current_product_name相同的表,那么我可以包含一个php文件。这是我已经连接到数据库的代码。检查表是否存在,然后包含php else not

<?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."; } 
?> 

回答

0

很容易。 查询您的数据库以查看表是否存在。如果确实如此,你会得到真实的回报。如果真的包括那个。

+0

如果存在?你是这个意思吗?我的PHP抛出一个错误。 –