gpt4 book ai didi

php - Phalcon - 原始查询插入语法错误

转载 作者:可可西里 更新时间:2023-11-01 07:55:56 25 4
gpt4 key购买 nike

我有以下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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com