Koahana框架,查询生成器

时间:2016-05-07 13:17:52

标签: php sql kohana query-builder

我是这样的纯SQL查询:

SELECT concat(tyres, '-', engine, '-', body) as product, `date`, `type`, `note`
FROM `products` LEFT JOIN `shop`.`users` ON `user_id` = `shop`.`user`.`id`

并且,我在以下示例中使用Kohana查询构建器

DB::select(array(DB::expr('concat(tyres, engine, body)'), 'product'))->from('products')->join('shop'.'users','LEFT')->on('user_id', '=', 'shop.users.id');

所以,kohana的查询不起作用。请帮忙

1 个答案:

答案 0 :(得分:1)

您始终可以使用调试来查找错误。

您加入条件错误您需要单个字符串才能输入数据库名称和表名。 将join('shop'.'users','LEFT')替换为join ( 'shop.users', 'LEFT' )

$query = DB::select ( array (
        DB::expr ( 'concat(tyres, engine, body)' ),
        'product' 
) )->from ( 'products' )->join ( 'shop.users', 'LEFT' )->on ( 'user_id', '=', 'shop.users.id' );
echo Debug::vars ( $query->compile () );

以下是:

string(125) "SELECT concat(tyres, engine, body) AS `product` FROM `products` LEFT JOIN `shop`.`users` ON (`user_id` = `shop`.`users`.`id`)"