php - 数据库中的未知列问题

标签 php mysql

请帮我解决我遇到的这个问题。我在 'where 子句' 中得到 '未知列 'the_mother_church_id' 。 我已经多次检查数据库中的列名的名称,并且我确定名称是相同的。

请问问题出在哪里。

谢谢

<?php
   $past = mysql_query("SELECT * FROM the_mother_church WHERE the_mother_church_id = '1'") or die(mysql_error()); 
?>

创建表

CREATE TABLE IF NOT EXISTS `the_mother_church` (
  ` the_mother_church_id` int(255) NOT NULL,
  `the_mother_church_head` varchar(255) NOT NULL,
  ` the_mother_church_content` varchar(3000) NOT NULL,
  ` the_mother_church_tags` varchar(255) NOT NULL,
  ` the_mother_church_created` datetime NOT NULL,
  ` the_mother_church_image` blob NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

最佳答案

(升级到答案)

您的 CREATE TABLE 语句显示该列的命名方式在起始引号和字段名称之间有一个空格:` the_mother_church_id`。要么:

  1. 在查询中使用带有空格的列名称:

    SELECT * FROM the_mother_church WHERE ` the_mother_church_id` = '1'
    
  2. 重命名列:

    ALTER TABLE `the_mother_church`
      CHANGE ` the_mother_church_id`
              `the_mother_church_id`      int(255)      NOT NULL,
      CHANGE ` the_mother_church_content`
              `the_mother_church_content` varchar(3000) NOT NULL,
      CHANGE ` the_mother_church_tags`
              `the_mother_church_tags`    varchar(255)  NOT NULL,
      CHANGE ` the_mother_church_created`
              `the_mother_church_created` datetime      NOT NULL,
      CHANGE ` the_mother_church_image`
              `the_mother_church_image`   blob          NOT NULL;
    

关于php - 数据库中的未知列问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10410088/

相关文章:

php - 无法访问获取 dBase 数据。登录页面不断循环回到同一页面

mysql - 不使用sql选择不满足条件的id

mysql - 索引和嵌套连接

php - 在 Php $db->select 上选择数据库

mysql - 我应该对许多分类行使用单个表吗?

MySQL UNHEX 函数在 phpmyadmin 中显示意外结果

php - 防止注销后显示以前的页面

php - Facebook PHP SDK getUser() 方法即使在从 facebook 取消授权应用程序后也会返回 uid

php - 使用 PDO 在一个表中查找记录并将数据追加到另一个表中

php - PHP中看似多态的东西真的是多态吗?