laravel4-datatables-package icon indicating copy to clipboard operation
laravel4-datatables-package copied to clipboard

SQLSTATE[HY000]: General error: 2031 for join query with 'where'

Open tony-was opened this issue 10 years ago • 3 comments

I ahve the following code snippet:

->leftJoin('blocked_users', function($join) use ($user_id, $id) { $join->on('users.id', '=', 'blocked_users.blocked_user_id') ->where('blocked_users.user_id', '=', $user_id); })

which throws the errors

SQLSTATE[HY000]: General error: 2031 (SQL: select count(*) as aggregate from...

not sure if anyone else is experiencing this.

tony-was avatar Dec 31 '14 06:12 tony-was

Try to use Eloquent in a simpler way?

->leftJoin('blocked_users', 'blocked_users.blocked_user_id','=',$user_id)

And I don't think it is a problem of bllim/laravel4-datatables-package. I would suggest you check Laravel documentation for more details.

CarterZhou avatar Jan 02 '15 01:01 CarterZhou

@CarterZhou If I run that it gives me an "Unknown Column" error as the last attribute needs to be a column name and not an actual value.

Though I think you are right I will need to re factor this to make it a little cleaner

tony-was avatar Jan 03 '15 08:01 tony-was

Try it:

        'options'   => [
            \PDO::ATTR_EMULATE_PREPARES => true
        ] 

Put it on your database config if you are using mysql

brunoerg avatar Mar 27 '18 18:03 brunoerg