How to use MySQL functions in Propel

后端 未结 2 720
失恋的感觉
失恋的感觉 2021-01-13 07:56

I want to select records that are 1 month old or newer.

The query is: SELECT * FROM foobar WHERE created_at > DATE_SUB(curdate(), INTERVAL 1 MONTH)

Using Pro

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-13 08:44

    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.

提交回复
热议问题