How to use MySQL functions in Propel

限于喜欢 提交于 2019-12-01 05:56:37

I think there is no option more than using Criteria::CUSTOM or doing a custom SQL query like this:

$con = Propel::getConnection(DATABASE_NAME);

$sql = "SELECT foobar.* FROM foobar WHERE created_at > DATE_SUB(curdate(), INTERVAL 1 MONTH)";  
$stmt = $con->prepare($sql);
$stmt->execute();

$books = FoobarPeer::populateObjects($stmt);

That's because Propel tries to be DBMS-agnostic, to help migration by doing a simple configuration value change, so it doesn't have any DBMS specific functions built in.

just replace the mysql date code you are using there with a precalculated php variable that has that date in it already.

i.e.

$monthAgo = '2008-10-03';
$c = new Criteria
$c->add(FoobarPeer::CREATED_AT, $monthAgo, Criteria::GREATER_THAN); 

obviously, you should dynamically calculate the date in php, rather than hard coding it, but you get the picture.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!