2013-10-06 3 views
1

업데이트 된 SQL : 환경은 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 구문에 오류가 있습니다. 올바른 구문이 'AND tt.user_id = 2 AND f.forum_id = ft.forum_id AND ft.user_id = 2'근처에서 사용하도록 MySQL 서버 버전에 해당하는 설명서를 확인하십시오. 1 행의 LEFT JOIN '[1064] – Mark

관련 문제