正在制作猎鹰4号。x与PHP 7。x,我试图做一个PHQL查询INSERT.
$phql = "INSERT INTO example
(
user_id,
answer,
date_last
) VALUES (
:user_id:,
:answer:,
NOW(),
) ON DUPLICATE KEY UPDATE answer = :answer:, date_last = NOW()";
使用modelsManager
$records = $this->modelsManager->executeQuery(
$phql,
[
'user_id' => $parameters['user_id'],
'answer' => $parameters['answer']
]
);
但是,Phalcon抛出以下错误:
语法错误,意外令牌ON,靠近' DUPLICATE KEY UPDATE 'answer = 1, date_last = NOW()',当解析时:INSERT INTO
任何来自Phalcon社区的人可能知道这是否可能?
感谢我相信,写这篇文章的时候。PHQL不支持。我的解决方案如下:
使用Phalcon的底层数据库适配器
$connection = new DbPdoMysqlAdapter($dbConfig);
$sql = "INSERT INTO example
(
user_id,
answer,
date_last
) VALUES (
?,
?,
NOW()
) ON DUPLICATE KEY UPDATE answer = ?, date_last = NOW()";
$result = $connection->query(
$sql,
[
$parameters['user_id'],
$parameters['answer'],
$parameters['answer']
]
);
var_dump($result);
工作现在!参考https://docs.phalcon.io/4.0/en/api/phalcon_db db-abstractdb