mysql查询有什么问题

时间:2012-02-08 20:40:02

标签: mysql select

我的MySQL查询有什么问题?什么东西立即跳出来对你不好?我也不完全清楚AS的作用和。在查询中的单词之间。 UNIX_TIMESTAMP(“日期”)也假设有“”约会?

$query = '
        SELECT 
            object_pk, 
            project_object_fk, 
            tbl_object.name 
        AS 
            name, 
            priority, 
            tbl_category.name 
        AS 
            category_name, 
            UNIX_TIMESTAMP("date") 
        AS 
            "date", 
            time, 
            login_pk, 
            concat_ws(" ", title, first_name, middle_name, last_name, suffix) 
        AS 
            person 
        FROM 
            tbl_object, 
            tbl_object_type, 
            tbl_task, 
            tbl_category, 
            tbl_object_category_link, 
            tbl_login, 
            tbl_contact 
        WHERE 
            UNIX_TIMESTAMP("date")>1327791600 
        AND 
            UNIX_TIMESTAMP("date")<1331420399 
        AND 
            object_type="task" 
        AND 
            tbl_task.object_fk=object_pk 
        AND 
            object_type_pk=object_type_fk 
        AND 
            tbl_object_category_link.object_fk=object_pk 
        AND 
            category_fk=category_pk 
        AND 
            login_owner_fk=login_pk 
        AND 
            contact_pk=contact_fk 
        AND 
            object_status="ACTIVE" 
        ORDER BY 
            time
    ';

2 个答案:

答案 0 :(得分:1)

更改mysql查询内容的引号。

使用“用于php字符串引用,或\”用于php'引用字符串中的sql字符串值

答案 1 :(得分:0)

UNIX_TIMESTAMP("date") 
AS 
"date",  <-- probably this line

将其更改为:

UNIX_TIMESTAMP("date") 
AS 
`date`,

为了安全起见。