如何在cakephp 3中的SQL查询中添加`字符 [英] how to add ` character to sql queries in cakephp 3
本文介绍了如何在cakephp 3中的SQL查询中添加`字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有特殊字段名称的表,例如'from'和'order'
I have a table with special fields name such as 'from' and 'order'
(此表与另一个cms一起使用,我不能更改表构造函数)
(this table used with another cms and I can't change table structor)
我想使用cakephp 3添加一条记录,但出现数据库错误。
I want add a record using cakephp 3 ,but I got 'Database Error'.
Cakephp 3的查询未使用`字符进行消毒!
it seems queries of cakephp 3 is not sanintized with ` character!
我在控件中的代码:
$tour = $this->Tours->patchEntity($tour, $this->request->data);
$this->Tours->save($tour);
生成的SQL是:
INSERT INTO tour_tours
(title, from , to, description, duration)
VALUES
('tour title', 'from', 'to', 'description of tour', 7)
SQL查询语法错误...
SQL Query has syntax error...
我该怎么办?
推荐答案
您需要添加
'quoteIdentifiers'=>文档中所述的数据源配置中的真实
You need to add
'quoteIdentifiers' => true
in your datasource configuration as stated in the doc
http://book.cakephp.org/3.0/en/orm/database-basics.html#configuration
这篇关于如何在cakephp 3中的SQL查询中添加`字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文