php 是什么导致了这个“MySQL 错误 #1054 - 未知列”错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5120634/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:52:01  来源:igfitidea点击:

What is causing this "MySQL error #1054 - Unknown column" error?

phpmysqlsqlmysql-error-1054

提问by Pedro

I'm having a little problem with this MySQL query. I've already used an suggestion I've seen in another question but still doesn't work....

这个 MySQL 查询有点问题。我已经使用了我在另一个问题中看到的建议,但仍然无效....

Here's the code

这是代码

$kernel->db->query( "UPDATE `" . TABLE_PREFIX . "users` 
                        SET `total_downs` = `total_downs` + 1 
                      WHERE `phcdl_files`.`file_author` = " . $file['file_author'] );

Which gives

这使

Invalid SQL Query
Unknown column 'phcdl_files.file_author' in 'where clause' (MySQL error no; 1054)


“where 子句”中的无效 SQL 查询未知列“phcdl_files.file_author”(MySQL 错误号;1054)

回答by glomad

That means that the column file_author doesn't exist in the table phcdl_files. You probably want

这意味着表 phcdl_files 中不存在列 file_author。你可能想要

$kernel->db->query( "UPDATE " . TABLE_PREFIX . "users SET total_downs = total_downs + 1 WHERE file_author = " . $file['file_author'] );

EDIT: please see the comment by Byron Whitlock above. You generally don't want to insert a variable directly into a SQL query string.

编辑:请参阅上面 Byron Whitlock 的评论。您通常不希望将变量直接插入到 SQL 查询字符串中。

回答by Dan J

If phcdl_filesis the name of a table, you need to includethat table in your query, and express some relationship between it and the rows in TABLE_PREFIXusersthat you want to update.

如果phcdl_files是表的名称,则需要在查询中包含该表,并表达它与TABLE_PREFIXusers要更新的行之间的某种关系。

回答by beta

where is phcdl_files.file_author?

在哪里 phcdl_filesfile_author?

 "UPDATE `" . TABLE_PREFIX . "users` 
          SET `total_downs` = `total_downs` + 1 
          WHERE `user`.`file_author` = " . $file['file_author']

and $file['file_author'] should come from phcdl_files table

和 $file['file_author'] 应该来自 phcdl_files 表