TYPO3 extbase数据库查询

时间:2015-05-16 09:21:44

标签: typo3 extbase typo3-6.2.x queryinterface

我有一个如下所示的extbase数据库查询。

$query = $this->createQuery();        
$result = $query->statement("Select * FROM table1 WHERE hidden = 0 AND deleted = 0 AND (".$PublicationYears.") AND logo != '' ORDER BY uid ASC LIMIT 0, ".$iLimit." ")->execute();             
return $result;


$PublicationYears = "ttra = '12' or ttra = '13' or ttra = '14'";

我将此查询转换为如下,

$query = $this->createQuery();

$query->getQuerySettings()->setRespectStoragePage(FALSE);

$query->matching( $query->logicalAnd(
       $query->equals('deleted', 0),
       $query->equals('hidden', 0)
    ));

$query->matching($query->logicalAnd($PublicationYears));

$query->matching($query->logicalNot(
     $query->equals('logo', '')
 ));

$query->setOrderings(array('uid' => Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING));

$query->setLimit((integer)$iLimit);
$Result = $query->execute();

return $Result;

但结果查询不包含与

相关的查询部分
$query->matching($query->logicalAnd($PublicationYears));

我认为上述查询中还存在其他错误。

请帮我创建正确的查询。

提前致谢。

2 个答案:

答案 0 :(得分:9)

首先你不需要这个

$query->matching( $query->logicalAnd(
   $query->equals('deleted', 0),
   $query->equals('hidden', 0)
));
根据ext_tables.php中表格的设置,

disable fields包含在默认查询中

多重匹配不起作用 导致你的第三次匹配

$query->matching($query->logicalNot(
 $query->equals('logo', '')
 ));

会覆盖之前使用的matching() 字符串logicalAnd?它不会工作

在你的情况下,你只需要把所有内容放在logicalAnd中就像这样做

$constraints = array();
$subConstraints = array();
$subConstraints[] = $query->equals('ttra', 12);
$subConstraints[] = $query->equals('ttra', 13); 
$subConstraints[] = $query->equals('ttra', 14);
$constraints[] = $query->logicalOr($subConstraints);
$constraints[] = $query->logicalNot(
     $query->equals('logo', '')
 ));

$query->matching($query->logicalAnd($constraints));

答案 1 :(得分:0)

对于您的PublicationYears值,您必须在匹配中进行制作或查询,如下所示: 我认为它可能仅适用于PublicationYears变量。

 $query->matching($query->logicalAnd(
            $query->logicalOr(
                $query->equals('ttra', 12)           
            ),
            $query->logicalOr(
                $query->equals('ttra', 13)           
            ),
            $query->logicalOr(
                $query->equals('ttra', 14)           
            ),
        ));