我正在尝试从数据库中选择数据,不幸的是我收到以下错误:
“语法错误或访问冲突: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 行 ”
以下是我在控制器内所做的事情:
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);
} Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
to是mysql中的保留关键字。您应该用反引号将 to 换行。$client_data = DB::select('SELECT `merchant_name`,`to`,`amount`,`from`,`date`,`status`,`provider` from `api_transactions` WHERE `to`=?', [$merchant_id]);