0

因此,当我运行活动记录查询时,我遇到了一个奇怪的错误(或者我可能只是愚蠢)。看看这个:

$results = $this->db->
  select('cd.casino_name, cd.casino_opened, cd.casino_latitude, cd.casino_longitude')->
  from('casino_data as cd, casino_cities as cc')->
  where('cd.city_id',$city_id)->
  where('cd.city_id=cc.city_id')->
  get()->result_array();

然后我明白了:

Error Number: 1054

Unknown column 'cd.city_id=cc.city_id' in 'where clause'

SELECT `cd`.`casino_name`, `cd`.`casino_opened`, `cd`.`casino_latitude`, `cd`.`casino_longitude`
FROM (`m_casino_data` as cd, `m_casino_cities` as cc)
WHERE `cd`.`city_id` =  1
AND `cd`.`city_id=cc`.`city_id`

Filename: httpdocs/_dev/libraries/Test.php

Line Number: 649

发生了什...

帮助请...谢谢

4

2 回答 2

1

问题在于 where 子句

$results = $this->db->
select('cd.casino_name, cd.casino_opened, cd.casino_latitude, cd.casino_longitude')->
from('casino_data as cd, casino_cities as cc')->
where('cd.city_id',$city_id)->
where('cd.city_id','cc.city_id')->//this would produce WHERE cd.city_id = cc.city_id
get()->result_array();
于 2012-05-13T04:07:05.787 回答
0

CodeIgniter 的 AR 保护有时效果不佳。在这种情况下,我认为您应该使用可选参数FALSE来避免自动保护。但并非所有函数都接受这个参数——但是where是的!

$this->db->where()接受可选的第三个参数。如果您将其设置为FALSE,CodeIgniter 将不会尝试使用反引号保护您的字段或表名称。

请参阅文档(您可以在附近找到4. Custom string)。

于 2012-05-13T07:09:11.793 回答