- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有以下INSERT
代码:
$reservationSuccess = $app->modelsManager->executeQuery(
"INSERT INTO MastersReservedTime (master_id, service_id, date, time, desc)
VALUES (:master_id:, :service_id:, :date:, :time:, :desc:)",
array(
'master_id' => $OrderCommit->master_id,
'service_id' => $oneService -> service_id,
'date' => $OrderCommit->date,
'time' => $startTime,
'desc' => $desc
)
);
此代码生成以下错误消息:
PHP Fatal error: Uncaught exception 'Phalcon\Mvc\Model\Exception' with message 'Syntax error, unexpected token DESC, near to ')\r\n VALUES (:master_id:, :service_id:, :date:, :time:, :desc:)', when parsing: INSERT INTO MastersReservedTime (master_id, service_id, date, time, desc)\r\n VALUES (:master_id:, :service_id:, :date:, :time:, :desc:) (209)' in /var/www/api/v1.0/index.php:1827\nStack trace:\n#0 [internal function]: Phalcon\Mvc\Model\Query->parse()\n#1 [internal function]: Phalcon\Mvc\Model\Query->execute()\n#2 /var/www/api/v1.0/index.php(1827): Phalcon\Mvc\Model\Manager->executeQuery('INSERT INTO Mas...', Array)\n#3 [internal function]: {closure}()\n#4 /var/www/api/v1.0/index.php(1961): Phalcon\Mvc\Micro->handle()\n#5 {main}\n thrown in /var/www/api/v1.0/index.php on line 1827
可能导致问题的原因是什么?提前致谢!
最佳答案
Desc 是 MySQL reserved word .使用原始查询时,您必须转义保留字。要在 PHQL 中转义它们,您必须将它们括在方括号 [] 中。
像这样重写您的查询将有效:
INSERT INTO MastersReservedTime (master_id, service_id, date, time, [desc])
VALUES (:master_id:, :service_id:, :date:, :time:, :desc:)
注意上面的[desc]
。
来自文档的信息:https://docs.phalconphp.com/en/latest/reference/phql.html#escaping-reserved-words
关于php - Phalcon - 原始查询插入语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38742415/
我是一名优秀的程序员,十分优秀!