简体   繁体   English

MySQL未知列错误,但结果似乎还可以,并且查询在phpMyAdmin中有效

[英]MySQL Unknown column error, but results seem ok, and query works in phpMyAdmin

This is very strange. 这很奇怪。 I am using MySQLi in PHP 5, and when executing the following query, i end up with an error in my httpd log similar as follows 我在PHP 5中使用MySQLi,执行以下查询时,我的httpd日志中出现错误,如下所示

[error] [client 192.168.0.1] Unknown column 'memberid' in 'where clause', referer: http://www.example.com/app/add-device
[error] [client 192.168.0.1] fetch_row[0] failed, referer: http://localhost/app/add-device

The query itself 查询本身

$this->db->query('
                            SELECT
                                `members`.`id`,
                                `members_timezones`.`timezone`,
                                `members`.`memberid`
                            FROM
                                `members`
                            RIGHT JOIN
                                `members_timezones` ON `members_timezones`.`memberid` = `members`.`id`
                            WHERE
                                `members`.`systemid` = ' . SYSTEM_ID . '
                                AND
                                `members`.`memberid` = ' . intval($this->user->uid)  . '
                                AND
                                `members`.`user` IS NULL
                            LIMIT 1
                        ');

Just to clarify, the above query does respond with expected results, however my httpd log is being spammed with an error that claims that column does not exist when it does. 只是为了澄清一下,以上查询的确会以预期的结果响应,但是我的httpd日志被垃圾邮件泛滥,并出现错误,声称该列不存在。 It is also claiming that 'fetch' is not returning anything -- it does as well. 它还声称“获取”没有返回任何内容,它也一样。

I would like to eliminate this false error from my system. 我想从系统中消除此错误错误。

----- ADDED ------ - - - 添加 - - -

The query results 查询结果

id  timezone    memberid
12  America/New_York    2

The query results (EXPLAIN) 查询结果(EXPLAIN)

id  select_type table   partitions  type    possible_keys   key key_len ref rows    Extra
1   SIMPLE  members_timezones   NULL    ALL NULL    NULL    NULL    NULL    2    
1   SIMPLE  members NULL    eq_ref  PRIMARY PRIMARY 4   linked24.members_timezones.memberid 1   Using where

members 成员

Column  Type    Comment
id  int(11) Auto Increment   
details text NULL    
user    varchar(35) NULL     
pass    varchar(512) NULL    
entered timestamp NULL [0000-00-00 00:00:00]     
updated timestamp NULL   
pass_key    varchar(32) NULL
systemid    int(11)  
memberid    int(11)

members_timezones Members_timezones

Column  Type    Comment
id  int(11) Auto Increment   
memberid    int(11)  
timezone    varchar(80) [UTC]

I was able to resolve this issue by aliasing all the fields in use. 我能够通过使用别名来解决所有问题。

SELECT Table.Field As Field FROM Table

Not sure as to why this worked, but I am content that there is no further errors being reported. 不确定为什么这样做,但是我很满意没有进一步的错误报告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM