通过PHP检查MySQL表中是否存在列 [英] Check if column exist in Mysql table via php
本文介绍了通过PHP检查MySQL表中是否存在列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了mysql表,并在其中放置了一些列.
I created mysql tables and there I have put some columns.
现在,我想通过php检查数据库中是否存在某个列.
Now I want to check that a certain column exists in the database via php.
赞:
if (column exist){
echo "Column in table is available."
}
else{
echo "Column doesnt exist.";
}
有可能这样做吗?
非常感谢您的宝贵时间:)
A lot of thanks for your time :)
推荐答案
尝试
$result = mysql_query("SHOW COLUMNS FROM `table` LIKE 'fieldname'");
$exists = (mysql_num_rows($result))?TRUE:FALSE;
if($exists) {
// do your stuff
}
更多信息:- MySQL,检查如果使用SQL的表中存在一列
注意:-不推荐使用mysql_ *使用mysqli
或PDO
Note:- mysql_* is deprecated use mysqli
or PDO
这篇关于通过PHP检查MySQL表中是否存在列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文