2017-12-13 2 views
0

안녕하세요이 같이 및 웅변 사용하지 않고 Laravel 5.5 쿼리 빌더에서 변환해야하고 매김Laravel 5.5의 복잡한 쿼리 작성기?

select lt.country_name, u.user_id, u.real_name from users u 
join lang_table lt on lt.language_id = u.country 
where not exists (select fr2 from friends where fr1 = 1 and fr2 = u.user_id and status = 1) and not exists(select fr1 from friends where fr2 = 1 and fr1 = u.user_id and status = 1) 
and u.user_id <> 1 
and u.country = 1 

다음과 같은 변종을 많이 시도하지만 매번 나에게 줄을 가질 필요가있어 원시 쿼리 누군가가 나를 도울 수 있다면 오류가 발생합니까?

$data = DB::table('users') 
       ->join('lang_table','lang_table.language_id', '=' ,'users.country') 
      ->select('lang_table.country','users.user_id','users.real_name') 
       ->select(DB::raw(where not exists (select fr2 from friends where fr1 = 1 and fr2 = u.user_id and status = 1) and not exists(select fr1 from friends where fr2 = 1 and fr1 = u.user_id and status = 1) 
and u.user_id <> 1 
and u.country = 1)) 
       ->paginate(25); 
+1

받은 오류는 무엇입니까? – Jerodev

+0

SQLSTATE [4200] : 구문 오류 또는 액세스 위반 : 1064 SQL 구문에 오류가 있습니다. MariaDB 서버 –

+0

에 해당하는 설명서를 확인하십시오. 쿼리 작성기에서 문제가 존재하지 않는 절에서 왔다고 생각합니다. 내가 생각하는이 명령의 아날로그가 있고 DB :: raw는 어떤 이유로 받아 들여지지 않는다. –

답변

0

시도 내가이 요청을 작성하는 관리

'mysql' => [ 
      'driver' => 'mysql', 
      'host' => env('DB_HOST', '127.0.0.1'), 
      'port' => env('DB_PORT', '3306'), 
      'database' => env('DB_DATABASE', ''), 
      'username' => env('DB_USERNAME', ''), 
      'password' => env('DB_PASSWORD', ''), 
      'unix_socket' => env('DB_SOCKET', ''), 
      'charset' => 'utf8mb4', 
      'collation' => 'utf8mb4_unicode_ci', 
      'prefix' => '', 
      'strict' => false, 
      'engine' => null, 
     ], 
0

구성 \의 database.php에서 false로 엄격한 변경하고 지금 나에게

입력 오류 다음과 같은 오류 제공합니다 : 인수 1에 전달을 C : \ xampp \ htdocs \ findfriends \ vendor \ laravel \ framework \ src \ Illuminate \ Database \ Con nection.php에서 호출 된 array 형식의 null이어야합니다. 온라인 665

DB::select(`lt.country_name`,`u.user_id`,`u.real_name`) 
     ->from(`users as u`) 
     ->join(`lang_table as lt`, function($join) { 
      $join->on(`lt.language_id`, `=`, `u.country`); 
      }) 
     ->whereRaw(`not exists`, [], `(select fr2 from friends where fr1 = 1 and fr2 = u.user_id and status = 1)`) 
     ->whereRaw(`not exists (select fr1 from friends where fr2 = 1 and fr1 = u.user_id and status = 1)`, [], `and`) 
     ->where(`u.user_id`, `<>`, 1) 
     ->where(`u.country`, `=`, 1) 
     ->paginate(25);