TYPO3 - MySQL到mm查询语法

时间:2013-06-09 12:38:02

标签: typo3

我现在有一个工作的MySQL查询我需要它转换为Typo3语法

SELECT 
  tt_news_tx_extendnews_subscriber_mm.uid_local, 
  fe_users.* 
FROM fe_users
   JOIN tt_news_tx_extendnews_subscriber_mm
    ON tt_news_tx_extendnews_subscriber_mm.uid_foreign =  fe_users.uid
WHERE tt_news_tx_extendnews_subscriber_mm.uid_local = 101

TYPO3

        $res0 = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(
            'tt_news_tx_extendnews_subscriber_mm.uid_local,fe_users.*',
            'fe_users',
            'tt_news_tx_extendnews_subscriber_mm',
            'tt_news_tx_extendnews_subscriber_mm.uid_foreign = fe_users.uid',
            'tt_news_tx_extendnews_subscriber_mm.uid_local = 101',
            '',
            '',
            ''
        );  

结果是空的......有人知道这与typo3一起工作吗?

Debug带来:$ GLOBALS ['TYPO3_DB'] - > debug_lastBuiltQuery;

SELECT tt_news_tx_extendnews_subscriber_mm.uid_local,fe_users.* 
    FROM fe_users,tt_news_tx_extendnews_subscriber_mm,tt_news_tx_extendnews_subscriber_mm.uid_foreign = fe_users.uid 
    WHERE fe_users.uid=tt_news_tx_extendnews_subscriber_mm.uid_local 
    AND tt_news_tx_extendnews_subscriber_mm.uid_foreign = fe_users.uid.uid=tt_news_tx_extendnews_subscriber_mm.uid_foreign tt_news_tx_extendnews_subscriber_mm.uid_local = 101

1 个答案:

答案 0 :(得分:4)

通过exec_SELECT_mm_query,第4个参数是外键表名,而不是引用。你需要而不是:

tt_news_tx_extendnews_subscriber_mm.uid_foreign = fe_users.uid

fe_users

TYPO3 api : exec_SELECT_mm_query中查看更多详情。

我想,您可以尝试以下方法:

$res0 = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(
            'tt_news_tx_extendnews_subscriber_mm.uid_local,fe_users.*',
            'tt_news',
            'tt_news_tx_extendnews_subscriber_mm',
            'fe_users',
            'tt_news_tx_extendnews_subscriber_mm.uid_local = 101',
            '',
            '',
            ''
        );  

或者您可以使用以下小技巧完全使用SQL,因为exe_SELECTquery仅将您的字符串连接到SELECT..., FROM...(等等......)部分。因此,您可以在JOIN部分使用FROM

$res0 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tt_news_tx_extendnews_subscriber_mm.uid_local,fe_users.*',
'fe_users
   JOIN tt_news_tx_extendnews_subscriber_mm
    ON tt_news_tx_extendnews_subscriber_mm.uid_foreign =  fe_users.uid',
 'tt_news_tx_extendnews_subscriber_mm.uid_local = 101',
 '',
 '',
 '');