2013-10-06 41 views
1

更新的SQL:Environment是MySQL 5.5。 SQL是通過phpBB抽象層生成的,但是當我看到SQL時它看起來有效。這個用於phpBB的SQL有什麼問題?

SELECT f.*, t.*, p.*, u.*, tt.mark_time AS topic_mark_time, ft.mark_time AS forum_mark_time 
FROM (phpbb_posts p CROSS JOIN phpbb_users u CROSS JOIN phpbb_topics t) LEFT JOIN 
phpbb_forums f ON (t.forum_id = f.forum_id) LEFT JOIN phpbb_topics_track tt ON 
(t.topic_id = tt.topic_id AND tt.user_id = 2) LEFT JOIN phpbb_forums_track ft ON 
(f.forum_id = ft.forum_id AND ft.user_id = 2) WHERE p.topic_id = t.topic_id AND 
p.poster_id = u.user_id AND p.post_time > 1380495918 AND p.forum_id IN (7, 6, 5, 3, 4, 2, 1) 
AND p.post_approved = 1 ORDER BY t.topic_last_post_time DESC, p.post_time LIMIT 
18446744073709551615 

錯誤是:

未知列 '的條款' 在 't.topic_id'[1054]

所有列名稱存在。所有表格都存在。所有別名都存在。

下面是相關的代碼:

$sql_array = array(
    'SELECT' => 'f.*, t.*, p.*, u.*, tt.mark_time AS topic_mark_time, ft.mark_time AS forum_mark_time', 

    'FROM'  => array(
     POSTS_TABLE => 'p', 
     USERS_TABLE => 'u', 
     TOPICS_TABLE => 't'), 

    'WHERE'  => "$topics_posts_join_sql 
       AND p.poster_id = u.user_id 
       $date_limit_sql 
       $fetched_forums_str 
       $new_topics_sql 
       $remove_mine_sql 
       $filter_foes_sql 
       AND p.post_approved = 1", 

    'ORDER_BY' => $order_by_sql 
); 

$sql_array['LEFT_JOIN'] = array(
    array(
     'FROM' => array(FORUMS_TABLE => 'f'), 
     'ON' => 't.forum_id = f.forum_id' 
    ), 
    array(
     'FROM' => array(TOPICS_TRACK_TABLE => 'tt', FORUMS_TRACK_TABLE => 'ft'), 
     'ON' => "t.topic_id = tt.topic_id AND tt.user_id = $user_id" 
    ), 
     array(
     'FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 
     'ON' => "f.forum_id = ft.forum_id AND ft.user_id = $user_id" 
    ) 
); 

$sql = $db->sql_build_query('SELECT', $sql_array); 
+0

更新了SQL和錯誤代碼。 – Mark

回答

0
t.topic_id = TOPICS_TRACK_TABLE.topic_i 

是錯誤的。確保它使用正確的別名tt

+0

修正了這個問題。錯誤:您的SQL語法有錯誤;檢查與您的MySQL服務器版本相對應的手冊,以便在'AND tt.user_id = 2 AND f.forum_id = ft.forum_id AND ft.user_id = 2'附近使用正確的語法。'LEFT JOIN'在第1行[1064] – Mark