我正在使用cakephp并创建这个条件:
$conditions = array("Userword.levelid"=>0, "Userword.userid"=>$this->Auth->user('UserId'),"date(Userword.date)"=>"DATE_SUB(CURDATE(),INTERVAL 0 DAY)");
$Userword = $this->paginate(null, $conditions);
使用此选择蛋糕:
`Userword`.`userwordid`, `Userword`.`userid`, `Userword`.`wordid`, `Userword`.`date`, `Userword`.`levelid`, `Word`.`wordid`, `Word`.`word`, `Word`.`meaning`, `User`.`UserId`, `User`.`Email`, `User`.`password`, `User`.`username`, `User`.`cell`, `User`.`web` FROM `userwords` AS `Userword` LEFT JOIN `words` AS `Word` ON (`Userword`.`wordid` = `Word`.`wordid`) LEFT JOIN `users` AS `User` ON (`Userword`.`userid` = `User`.`UserId`) WHERE date(`Userword`.`date`) = 'DATE_SUB(CURDATE(),INTERVAL 2 DAY)'
但由此选择mysql无法返回记录,因为此select中的cakephp在最后一段中使用此字符('
)。
当我删除此字符并在phpmyadmin
中测试此代码时,此代码返回行。下面的两张图片显示了这一点:
答案 0 :(得分:9)
只是不要把它分开作为键=>价值对:
$conditions = array(
...
'DATE(Userword.date) = DATE_SUB(CURDATE(), INTERVAL 0 DAY)'
);