uepg / laravel-sybase

Connection and Laravel Eloquent driver for Sybase
GNU General Public License v2.0
33 stars 18 forks source link

Multiple where clause in Laravel 5.3 #28

Closed lianghsun closed 7 years ago

lianghsun commented 7 years ago

Hi, thanks for such convenient package. I have a question, could we use multiple where clause? In Laravel doc, we can

$query->where([
    ['column_1', '=', 'value_1'],
    ['column_2', '<>', 'value_2'],
    [COLUMN, OPERATOR, VALUE],
    ...
])

But when I tried to do the same thing, it came out the error. Please correct me if I have wrong using, thanks!

mainginski commented 7 years ago

All you can do with standard Eloquent, you, in theory could do with laravel-sybase, the package works as a translator. This translation works directly in the query (and Builder) provided by Eloquent, such as a parser. If there was any problem of that kind, it probably was in the assembly (or by your mistake, or by mistake of the package). Can you transcribe the errors?

lianghsun commented 7 years ago

OK, it's wired. The code is as below:

$lists = Filght::where([['flight_name', '=', 'aaa'], ['no', '=', '0163']])->get();

then, the erros is:

QueryException in Connection.php line 769:
Undefined variable: new_binds (SQL: select * from [flights] where ([flight_name] = aaa and [no] = 0163))

any solution?

mainginski commented 7 years ago

i'll check!

galangnra commented 7 years ago

did you tried it using orWhere ? and the Code will be like this : $lists = Filght::where('flight_name', '=', 'aaa') ->orWhere('no', '=', '0163') ->get();

mainginski commented 7 years ago

This will work, however, it needs to be fixed this implementation of Laravel 5.3.

lianghsun commented 7 years ago

@galangnra It works, and the code like this works too : $lists = Filght::where('flight_name', '=', 'aaa')->Where('no', '=', '0163') ->get();

but, what i want is to dynamically get user's input to generate where sql statement, that is why i want to define an array could store multiple where clauses, like:

$stat = [
    ['column_1', '=', 'value_1'],
    ['column_2', '<>', 'value_2'],
    [COLUMN, OPERATOR, VALUE],
    ...
]
mainginski commented 7 years ago

This should work, but I'll do some more testing.