Syntax error or access violation - Laravel
P粉496886646
P粉496886646 2023-09-03 13:10:32
0
1
554
<p>I'm trying to select data from a database and unfortunately I'm getting the following error: </p> <p>"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 ”</p> <p>Here's what I'm doing inside the controller: </p> <pre class="brush:php;toolbar:false;">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); }</pre></p>
P粉496886646
P粉496886646

reply all(1)
P粉018548441

to is a reserved keyword in mysql. You should wrap to with backticks.

$client_data = DB::select('SELECT `merchant_name`,`to`,`amount`,`from`,`date`,`status`,`provider` from `api_transactions` WHERE `to`=?', [$merchant_id]);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template