이렇게 laravel 쿼리 작성기를 사용하고 있습니다.Laravel 쿼리 작성기가 값을 바인딩하지 않습니다.
$col1 = Input::get('col1','');
$col2 = Input::get('col2','');
$result = DB::table('table1')
->select('id', 'col1', 'col2', 'col3')
->whereRaw("col1 like '%?%'", [$col1])
->whereRaw("col2 like '%?%'", [$col2])
->orderBy($orderBy, $orderType) //orderBy=col1, ordeyType=ASC
->skip($ofset)->take($limit) //$ofser=0, $limit=10
->get();
나는 아무것도 얻지 못합니다. 만약 내가 toSql() 함수를 사용합니다. 나는이 SQL을 이런 식으로 얻고있다.
select `id`, `col1`, `col2`, `col3`
from `table1` where col1 like '%?%' and col2 like '%?%'
order by `col1` ASC limit 10 offset 0
물음표는 거기에 있으면 안된다. 값으로 대체해야합니다. 이 코드를 사용하여 디버깅했습니다.
Log::info(var_export(DB::getQueryLog(), true));
로그는 내가 바인딩 내가 뭔가를 잘못하고 있어요 홍보를 작동하지 않는 생각이
2 =>
array (
'query' => 'select `id`, `col1`, `col2`, `col3` from `table1` where col1 like \'%?%\' and col2 like \'%?%\' order by `col1` ASC limit 10 offset 0',
'bindings' =>
array (
0 => 'k',
1 => '',
),
'time' => 25.71,
처럼 보인다. 왜냐하면 내가 데이터베이스에서이 코드를 시도하면 작동한다.
select `id`, `col1`, `col2`, `col3` from `table1`
where col1 like '%k%' and col2 like '%%'
order by `col1` ASC limit 10 offset 0
감사가 – muhammedea
을 workd 내가이 더 많은 찬성 투표 수 있으면 좋겠다. 주변에 많은 잘못된 예가 있는데, 나는 손목을 자르려고하고 있었다. – Toskan