且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用PHP,PDO,MySQL检查列是否不存在?

更新时间:2023-11-26 08:44:28

我不知道它是否对您有帮助,但是您可以尝试以下方法:

I don't know if it helps you, but you can try this:

if (count($dbh->query("SHOW COLUMNS FROM `items` LIKE 'item_type'")->fetchAll())) {
    $sth = $dbh->query ("SELECT item_type FROM items WHERE user_id = '$user_id'");
    $row = $sth->fetch();
    $item_type = $row['item_type'];
} else {
    $item_type = null;
}

它检查该列是否存在并执行任务.

It checks if the column exists and performs the task.