【问题标题】:Is there any method or so in MySQLi to check if a column exists?MySQLi 中是否有任何方法可以检查列是否存在?
【发布时间】:2015-11-18 12:18:42
【问题描述】:

我想知道 mysql 表中是否存在特定列。我在较旧的帖子中搜索了解决方案,但没有任何运气:

  1. Check if column exist in Mysql table via php
  2. How can I check if mysql table column even exists?
  3. MySQL, Check if a column exists in a table with SQL
  4. Check if column exists, if not, add in MySQL through PHP

我想知道的是PHP的MySQLi类中是否有任何方法可以做到这一点?

问的原因是我现在的项目是基于PHP中的MySQLi类的。

我已经尝试过通过查询“information_schema”数据库来完成工作的旧方法,但由于某种原因,它没有成果。另外,我更喜欢 MySQLi 类的 PHP 内置方法来执行我的所有任务。

【问题讨论】:

  • information_schema.COLUMNS 如果列存在则返回一行,否则返回空结果

标签: php mysqli field


【解决方案1】:

有一个MySQL查询来获取列信息:

show columns from `table`;

这里有更多关于它的文档:https://dev.mysql.com/doc/refman/5.7/en/show-columns.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-18
    • 2011-01-17
    • 1970-01-01
    • 2018-07-28
    • 2017-02-16
    • 2017-10-24
    • 1970-01-01
    相关资源
    最近更新 更多