以下查詢從phpmyadmin運行時按預期返回一行。Kohana 3 - 查詢生成器給出0行
SELECT units . * , locations . *
FROM units, locations
WHERE units.id = '1'
AND units.location_id = locations.id
LIMIT 0 , 30
但是,當我嘗試做它的Kohana 3:
$unit = DB::select('units.*', 'locations.*')
->from('units', 'locations')
->where('units.id', '=', $id)->and_where('units.location_id', '=', 'locations.id')
->execute()->as_array();
var_dump($unit);
它打印
array(0) { }
我在做什麼錯?
echo Database :: instance() - > last_query;給我: SELECT'locations'。*,'units'。* FROM'units','locations' WHERE' units'.'location_id' ='locations.id'AND' units'.'id' ='1' 它看起來像bug應該是'locations'.'id'而不是'locations.id'??? 使用你所建議的普通查詢方法給了我以下錯誤: ErrorException [致命錯誤]:無法通過在線參考 傳遞參數2 「 - >綁定( ':身份證',(INT)$ ID)」 – pigfox 2010-06-01 00:56:56
@ OK,嗯嘗試刪除轉換爲整數,或確保$ id設置在某處(可以在之後,因爲它是通過引用傳遞) – alex 2010-06-01 01:08:37