MySQL未知列错误,但结果似乎没问题,查询在phpMyAdmin中有效

时间:2013-12-21 22:17:53

标签: php mysql mysqli

这很奇怪。我在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

查询本身

        $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
                        ');

为了澄清一下,上面的查询确实回应了预期的结果,但是我的httpd日志被垃圾邮件发送了一个错误,声称该列不存在。它还声称'fetch'没有返回任何东西 - 它也是如此。

我想从我的系统中消除这个错误错误。

----- ADDED ------

查询结果

id  timezone    memberid
12  America/New_York    2

查询结果(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

成员

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

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

1 个答案:

答案 0 :(得分:0)

我能够通过别名解决此问题。

SELECT Table.Field As Field FROM Table

不确定为什么会有效,但我很满意没有报告其他错误。