I'm trying to select data from a database and unfortunately I'm getting the following error:
"Syntax error or access violation: 1064 There is an error in your SQL syntax; please check the manual for your MariaDB server version for use around 'to,amount,from,date,status,provider from Correct syntax for api_transactions where=?' in file /home/nosi/myProjects/paylesotho/vendor/laravel/framework/src/Illuminate/Database/, line 1 (SQL: SELECT MerchantName,To,Amount from api_transactions , from, date, status, provider, where to=00000) Connection.php line 664 ”
Here's what I'm doing inside the controller:
public function TransactionDetails ($merchant_id){ $client_data = DB::select('SELECT merchant_name,to,amount,from,date,status,provider from api_transactions where to=?', [$merchant_id]); return response()->json($client_data); }
to
is a reserved keyword in mysql. You should wrap to with backticks.