我创建了 mysql 表并在其中放置了一些列。
现在我想通过 php 检查数据库中是否存在某个列。
像这样:
if (column exist){
echo "Column in table is available."
}
else{
echo "Column doesnt exist.";
}
这有可能吗?
非常感谢您的宝贵时间:)
最佳答案
尝试
$result = mysql_query("SHOW COLUMNS FROM `table` LIKE 'fieldname'");
$exists = (mysql_num_rows($result))?TRUE:FALSE;
if($exists) {
// do your stuff
}
更多信息:- MySQL, Check if a column exists in a table with SQL
注意:- mysql_* 不推荐使用 mysqli
或 PDO
关于php - 通过PHP检查MySQL表中是否存在列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23513479/