M. Badovsky
M. Badovsky

Reputation: 99

Koahana framework, query builder

I've pure sql query like this:

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

and, I using Kohana query builder in following example

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

so, kohana's query not working. Please help

Upvotes: 1

Views: 151

Answers (1)

Faraz
Faraz

Reputation: 761

You can always use debugging to find out error.

You are join condition is wrong you need single string to enter database name and table name. Replace join('shop'.'users','LEFT') with 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 () );

Here is out put:

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

Upvotes: 1

Related Questions