こんにちは。
MYSQLで作ったWebサービスをherokuに挙げた所、以下コード①の箇所でエラーとなりました。
恐らくherokuでpostgreを使用しているため、SQL文の ` が対応していないのではないかと思い、
生のSQL文からクエリビルダでの記法に修正しています。
以下②のように修正したのですが、最下部記載のエラーが出てしまいました。
エラー箇所は$query->where("months" & $request->month, "<>", "0");の行で、
"months" & $request->monthが期待通りに動いていないようです。
ここは "months" と $request->month を & でビット演算した結果が <> 0 (0以外)のレコードを抽出したいのですが、
クエリビルダを使用しての正しい書き方をご存知の方、ご教示いただけないでしょうか。
よろしくお願いいたします。
//①MYSQLで動いていた処理(生のSQL) $points = \DB::select("select * from `points` inner join `categorymonths` on `points`.`id` = `categorymonths`.`point_id` where `category` = '".$category."' and `months` & ".$month." <> 0"); //②postgreでも動くように上のSQLを修正(クエリビルダ) $points = \DB::table("points")->join("categorymonths", "points.id", "=", "categorymonths.point_id") ->where("category",$request->category) ->where(function($query) use ($request){ $query->where("months" & $request->month, "<>", 0); }) ->get();
エラー
SQLSTATE[42S22]: Column not found: 1054 Unknown column '!' in 'where clause' (SQL: select * from points
inner join categorymonths
on points
.id
= categorymonths
.point_id
where category
= dolphin and (!
<> 0))

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/29 07:46