我正在尝试从我的数据库中获取一些必须以间隔开始或结束的数据:
基本的 SQL 查询如下所示:
SELECT broadcast.id, broadcast.id_channel, broadcast.start_at, broadcast.real_start_at, broadcast.real_end_at, broadcast.title, broadcast.sended, FROM `broadcast`
WHERE (
(broadcast.real_start_at >= :p1 AND broadcast.real_start_at <= :p2)
OR
(broadcast.real_end_at >= :p3 AND broadcast.real_end_at <= :p4))
AND broadcast.sended=:p5 AND broadcast.id_plurimedia=:p6
LIMIT 50
推进查询是这个:
$broadcastsQuery = BroadcastQuery::create()
->limit(20);
->condition('cond1', 'broadcast.real_start_at >= ?', $this->date_start, \Criteria::GREATER_EQUAL)
->condition('cond2', 'broadcast.real_start_at <= ?', $this->date_end, \Criteria::LESS_EQUAL)
->combine(array('cond1', 'cond2'), \Criteria::LOGICAL_AND, 'cond3')
->condition('cond4', 'broadcast.real_end_at >= ?', $this->date_start, \Criteria::GREATER_EQUAL)
->condition('cond5', 'broadcast.real_end_at <= ?', $this->date_end, \Criteria::LESS_EQUAL)
->combine(array('cond4', 'cond5'), \Criteria::LOGICAL_AND, 'cond6')
->where(array('cond3', 'cond6'), null, 'OR');
->filterBySended(true)
->find();
当我执行我的脚本时,我遇到了这个错误:
Unable to execute SELECT statement [SELECT broadcast.id, broadcast.id_channel, broadcast.id_plurimedia, broadcast.id_aedra, broadcast.start_at, broadcast.real_start_at, broadcast.real_end_at, broadcast.title, broadcast.sended, broadcast.date_creation, broadcast.date_edition FROM `broadcast` WHERE ((broadcast.real_start_at >= :p1 AND broadcast.real_start_at <= :p2) AND (broadcast.real_end_at >= :p3 AND broadcast.real_end_at <= :p4)) AND broadcast.sended=:p5 LIMIT 50] [wrapped: Warning: PDOStatement::bindValue() expects parameter 3 to be long, string given in /var/www/projectKI/vendor/propel/propel1/runtime/lib/connection/DebugPDOStatement.php line 114] (500 Internal Server Error)
我真的不明白为什么会出现错误以及为什么我的查询有“AND”语句而不是“OR”。