search

Home  >  Q&A  >  body text

Syntax error or access violation - Laravel

<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粉496886646P粉496886646468 days ago547

reply all(1)I'll reply

  • P粉018548441

    P粉0185484412023-09-04 12:30:25

    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]);

    reply
    0
  • Cancelreply