Saneesh
4 months ago

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydb.users u' doesn't exist

Posted 4 months ago by Saneesh

Hi all, In my Laravel application, I'm trying to connect to another database(not the default database of my application). When I try to execute the following query it generates an error.

$query = DB::connection('user_management') ->table('users u') ->select(DB::raw('u.uid,u.uuid, ufd.name, ufd.mail, ufd.status, ufd.created, ufd.changed')) ->leftJoin('users_field_data ufd', 'u.uid', '=', 'ufd.uid') ->where('uid', '>', 10) ->orderBy('u.uid');

"SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydb.users u' doesn't exist (SQL: select u.uid,u.uuid, ufd.name, ufd.mail, ufd.status, ufd.created, ufd.changed from `users u` left join `users_field_data ufd` on `u`.`uid` = `ufd`.`uid` order by `u`.`uid` asc limit 3 offset 0)"

As you can see the error starts at the backtick(`). When I execute the same query (at it is) in MySQL console or in PHPStorm it shows the same error. If I remove all the backtics its working.

How can I fix this issue? is there any option to remove the backtick from the query before the execution in Laravel?

Regards, Saneesh.

Please sign in or create an account to participate in this conversation.