dourui9570 2010-05-31 21:33
浏览 50
已采纳

Kohana 3 - “查询”构建器提供0行

The following query returns one row as expected when run from phpmyadmin.

SELECT units .  * , locations .  *
FROM units, locations
WHERE units.id = '1'
AND units.location_id = locations.id
LIMIT 0 , 30 

But when I try to do it in 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);

It prints

array(0) { }

What am I doing wrong?

  • 写回答

2条回答 默认 最新

  • dongzhang1987 2010-05-31 23:27
    关注

    I can't immediately tell what is wrong with that query builder, however, checkout this for debugging purposes.

    After calling execute() on your db chain, try this.

    echo Database::instance()->last_query;
    

    This will show in plain SQL the last query performed. It will be worth looking at what the query builder generated, and how it differs to your SQL you used in phpmyadmin.

    If all else fails, just use the plain query methods.

    $query = "SELECT units .  * , locations .  *
    FROM units, locations
    WHERE units.id = :id
    AND units.location_id = locations.id
    LIMIT 0 , 30 ";
    
    $unit = Db::query(Database::SELECT, $query)
              ->bind(':id', (int) $id)
              ->execute()
              ->as_array();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测