简体   繁体   English

zend框架,其中使用regexp查询

[英]zend framework where query with regexp

I want to search for data within the database with these conditions 我想在这些情况下在数据库中搜索数据

SELECT * 
FROM SMS_Reports 
WHERE AWB_NO REGEXP '1500' 
   OR SMS_TEXT REGEXP 'SOME STRING' 
   OR Update_at LIKE '%some string%';

I want to query in the database with the above criteria please help me with the query for Zend framework 我想使用上述条件在数据库中查询,请帮助我进行Zend框架查询

here what I found and its work for me 在这里,我发现了什么,对我有用

$sql = new Sql($this->adapter);
    $select = $sql->select(array('t1' => $this->table));
    $select->columns(array(
        'From' => 'SMS_From',
        'AWB_NO',
        'Text' => 'SMS_TEXT',
        'Status',
        'Send_at' => new Expression('IF(t1.Update_at IS NOT NULL,t1.Update_at,"")')
    ));
    if (isset($data['search_string']) && !empty($data['search_string'])) {
        $date = date('Y-m-d',strtotime($data['search_string']));
        $select->where(array(
            new PredicateSet(
                array(
                    new PredicateExpression("Update_at = '".$date."'"),
                    new PredicateExpression("SMS_TEXT REGEXP '".$data['search_string']."'"),
                    new PredicateExpression("AWB_NO REGEXP '".$data['search_string']."'"),
                ),
                PredicateSet::COMBINED_BY_OR
            ),
        ));
    }
    $select->join(array('t2' => 'MST_Clients'),'t1.Client_ID = t2.Client_ID',
        array(
            'Client_Name' => new Expression('IF(t2.Client_Name IS NOT NULL,t2.Client_Name,"")'),
        ),'LEFT');
    // echo $sql->getSqlStringForSqlObject($select);die; 
    if($paging) {
        $dbAdapter = new DbSelect($select, $this->getAdapter ());
        $paginator = new Paginator($dbAdapter);
        return $paginator;
    }else {
        $smt = $sql->prepareStatementForSqlObject($select);
        $result = $this->resultSetPrototype->initialize($smt->execute())->toArray();
        return $result;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM