[英]Error in executing query in Phalcon but query works on phpMyAdmin
I have following table structure 我有以下表格结构
headline
is_user_article
is_approved
updated_date
created_date
I want to sort record in such a way that 我想以一种方式对记录进行排序
That means I want those articles at first which are user submitted(is_user_article=1) and is not approved (is_approved=0), then rest of the records ordered by updated date and created date. 这意味着我首先要让那些用户提交的文章(is_user_article = 1)未被批准(is_approved = 0),然后再按更新日期和创建日期排序其余记录。
I have following query 我有以下查询
<?php
$phql = "SELECT headline, is_user_article, created_date, updated_date, is_approved
FROM NewsRoom\Articles\Models\Articles ORDER BY
CASE is_approved WHEN 0 THEN is_user_article END DESC,
CASE WHEN is_approved = 1 THEN updated_date END DESC,
updated_date DESC,
created_date DESC";
$articles = $this->modelsManager->executeQuery($phql);
?>
PROBLEM 问题
The query doesnot work when I executed using Phalcon's modelManager
. 当我使用Phalcon's modelManager
执行时,查询Phalcon's modelManager
。 I get "Syntax error, unexpected token WHEN near is_approved=1"
我收到"Syntax error, unexpected token WHEN near is_approved=1"
However, if I execute this query in phpMyadmin replacing NewsRoom\\Articles\\Models\\Articles
with actual table name tbl_articles
, it works flawlessly. 但是,如果我在phpMyadmin中执行此查询,将NewsRoom NewsRoom\\Articles\\Models\\Articles
替换为实际的表名tbl_articles
,则它可以正常工作。
Can anybody help me on this. 有人可以帮我吗?
Change your SQL from 从更改SQL
CASE WHEN is_approved = 1 THEN updated_date END DESC,
to 至
CASE is_approved WHEN 1 THEN updated_date END DESC,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.