首頁  >  問答  >  主體

語法錯誤或存取衝突 - Laravel

<p>我正在嘗試從資料庫中選擇數據,不幸的是我收到以下錯誤:</p> <p>「語法錯誤或存取衝突:1064 您的SQL 語法有錯誤;請檢查與您的MariaDB 伺服器版本相對應的手冊,以了解在'to,amount,from,date,status,provider from 附近使用的正確語法api_transactions 在哪裡=?'在檔案/home/nosi/myProjects/paylesotho/vendor/laravel/framework/src/Illuminate/Database/ 中的第1 行(SQL:從api_transactions 中選擇商家名稱、到、金額金額、來自、日期、狀態、提供者,其中to=00000) Connection.php 第664 行 ”</p> <p>以下是我在控制器內所做的事情:</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粉496886646413 天前498

全部回覆(1)我來回復

  • P粉018548441

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

    to是mysql中的保留關鍵字。您應該用反引號將 to 換行。

    $client_data = DB::select('SELECT `merchant_name`,`to`,`amount`,`from`,`date`,`status`,`provider` from `api_transactions` WHERE `to`=?', [$merchant_id]);

    回覆
    0
  • 取消回覆