-
Notifications
You must be signed in to change notification settings - Fork 114
Open
Description
Hello, I just installed this library, but I encountered a problem with the examples in the documentation.
I tested the example of the LEFT JOIN
, but this didn't work:
<?php
use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder;
$builder = new GenericBuilder();
$query = $builder->select()
->setTable('user')
->setColumns([
'userId' => 'user_id',
'username' => 'name',
'email' => 'email',
'created_at'
])
->orderBy('user_id', OrderBy::DESC)
->leftJoin(
'news', //join table
'user_id', //origin table field used to join
'author_id', //join column
['newsTitle' => 'title', 'body', 'created_at', 'updated_at']
)
->on()
->equals('author_id', 1); //enforcing a condition on the join column
$query
->where()
->greaterThan('user_id', 5)
->notLike('username', 'John')
->end();
$query
->orderBy('created_at', OrderBy::DESC);
echo $builder->writeFormatted($query);
With some tweaks I managed to make it work, and it appears like so:
<?php
use NilPortugues\Sql\QueryBuilder\Builder\MySqlBuilder;
use NilPortugues\Sql\QueryBuilder\Syntax\OrderBy;
use NilPortugues\Sql\QueryBuilder\Syntax\Where;
$builder = new MySqlBuilder();
$query = $builder->select();
$query->setTable('user')
->setColumns([
'userId' => 'user_id',
'username' => 'name',
'email' => 'email',
'created_at'
])
->orderBy('user_id', OrderBy::DESC);
$query
->leftJoin(
'news', //join table
'user_id', //origin table field used to join
'author_id', //join column
['newsTitle' => 'title', 'body', 'created_at', 'updated_at']
)
->on()
->equals('author_id', 1) //enforcing a condition on the join column
->end();
$query
->where()
->greaterThan('user_id', 5)
->notLike('username', 'John')
->end()
->orderBy('created_at', OrderBy::DESC);
echo $builder->writeFormatted($query);
Is it different because I used MySqlBuilder or is there something wrong I can't understand?
Metadata
Metadata
Assignees
Labels
No labels