【问题标题】:Phalcon PHP Fatal Error: Uncaught exception with message 'Unknown Expression'Phalcon PHP 致命错误:未捕获的异常,带有消息“未知表达式”
【发布时间】:2014-05-17 06:14:49
【问题描述】:

我正在尝试遵循 REST 应用程序教程 provided by Phalcon,但是当我尝试插入数据时,我一直遇到问题。我的问题是我不知道这个错误应该是什么意思。我相信这是 Phalcon 中的一个错误,但我对 C 的了解是不存在的。如果我应该提供更多上下文,请告诉我。

以下是 PHP 错误日志中显示的错误:

PHP Fatal error:  Uncaught exception 'Phalcon\\Mvc\\Model\\Exception' with message 'Unknown expression' in /home/acarbonaro/testApplication/index.php:84\n
Stack trace:\n
0 [internal function]: Phalcon\\Mvc\\Model\\Query->_getExpression(274, false)\n
1 [internal function]: Phalcon\\Mvc\\Model\\Query->_prepareInsert()\n
2 [internal function]: Phalcon\\Mvc\\Model\\Query->parse()\n
3 [internal function]: Phalcon\\Mvc\\Model\\Query->execute(Array, NULL)\n
4 /home/acarbonaro/testApplication/index.php(84): Phalcon\\Mvc\\Model\\Manager->executeQuery('INSERT INTO Pro...', Array)\n
5 [internal function]: {closure}()\n
6 /home/acarbonaro/testApplication/index.php(115): Phalcon\\Mvc\\Micro->handle()\n
7 {main}\n
  thrown in /home/acarbonaro/testApplication/index.php on line 84

这是 POST 路由的代码,带有行号供参考。

71: $app->post('/api/products', function() use ($app) {
72:     if ($app->request->isPost() == true) {
73:         if ($app->request->isAjax() == true) {
74:             $product = $app->request->getJsonRawBody();
75:             $partNumber = $product->partNumber;
76:         }
77:         $partNumber = $app->request->getPost('partNumber');
78:     }
79: 
80:     $phql = "INSERT INTO Products (partNumber) VALUES (:partNumber:)";
81:     $params = array(
82:         'partNumber' => $partNumber
83:     );
84:     $status = $app->modelsManager->executeQuery($phql, $params);
85: 
86:     // Prep the response
87:     if ($status->success() == true) {
88:         $response->setStatusCode(201, "Created");
89: 
90:         $product->id = $status->getModel()->id;
91: 
92:         $response->setJsonContent(array('status' => 'OK', 'data' => $product));
93:     } else {
94:         $response->setStatusCode(409, "Conflict");
95: 
96:         // Send errors to the client
97:         $errors = array();
98:         foreach($status->getMessages() as $message) {
99:             $errors[] = $message->getMessage();
100:         }
101:  
102:         $response->setJsonContent(array('status' => 'ERROR', 'messages' => $errors));
103:     }
104:  
105:     return $response;
106: });

【问题讨论】:

    标签: php phalcon uncaught-exception


    【解决方案1】:
    80:     $phql = "INSERT INTO Products (partNumber) VALUES (:partNumber)";
    81:     $params = array(
    82:         ':partNumber' => $partNumber
    83:     );
    84:     $status = $app->modelsManager->executeQuery($phql, $params);
    

    我对你所说的这个 Phalcon 没有经验,但从堆栈跟踪来看,它似乎正在使用 PDO。

    第 80 行:删除了最后一个冒号以具有 ... VALUES (:partNumber)";

    第 82 行:在数组键的开头添加了一个冒号,因此您有 ':partNumber' =>

    这将是一个有效的 PDO prepare() 语句。您的里程可能会有所不同,但这是一个不错的起点。

    【讨论】:

    • 我切换到使用 PDO,但它引发了不同的错误。我认为使用 Phalcon 正确配置了 PHQL,这是 Phalcon 本身的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-09
    • 2013-08-24
    • 2012-04-25
    • 2015-01-04
    • 1970-01-01
    相关资源
    最近更新 更多