英文:
Syntax error or access violation - Laravel
问题
I am trying to select data from the database, unfortunately I am getting below error:
"语法错误或访问违规: 1064 您的SQL语法错误;请检查与您的MariaDB服务器版本相对应的手册,以了解在第1行使用正确的语法 near 'to,amount,from,date,status,provider from api_transactions where to=?' (SQL: SELECT merchant_name,to,amount,from,date,status,provider from api_transactions where to=00000) in file /home/nosi/myProjects/paylesotho/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 664"
Below is what I did 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);
}
英文:
I am trying to select data from the database, unfortunelety I am getting below error :
"Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'to,amount,from,date,status,provider from api_transactions where to=?' at line 1 (SQL: SELECT merchant_name,to,amount,from,date,status,provider from api_transactions where to=00000) in file /home/nosi/myProjects/paylesotho/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 664
"
Below is what I did 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);
}
答案1
得分: 1
to
在 MySQL 中是一个保留关键字。你应该使用反引号包裹 to
。
$client_data = DB::select('SELECT `merchant_name`, `to`, `amount`, `from`, `date`, `status`, `provider` from `api_transactions` WHERE `to`=?', [$merchant_id]);
英文:
to
is a reserved keyword in mysql. You should wrap to in backticks.
$client_data = DB::select('SELECT `merchant_name`,`to`,`amount`,`from`,`date`,`status`,`provider` from `api_transactions` WHERE `to`=?', [$merchant_id]);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论