使用正则表达式查询的 zend 框架
zend framework where query with regexp
我想在符合这些条件的数据库中搜索数据
SELECT *
FROM SMS_Reports
WHERE AWB_NO REGEXP '1500'
OR SMS_TEXT REGEXP 'SOME STRING'
OR Update_at LIKE '%some string%';
我想用上述条件在数据库中查询请帮我查询Zend框架
这里是我的发现和对我有用的东西
$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;
}
我想在符合这些条件的数据库中搜索数据
SELECT *
FROM SMS_Reports
WHERE AWB_NO REGEXP '1500'
OR SMS_TEXT REGEXP 'SOME STRING'
OR Update_at LIKE '%some string%';
我想用上述条件在数据库中查询请帮我查询Zend框架
这里是我的发现和对我有用的东西
$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;
}