使用Propel Symfony 2进行自定义查询


custom query with propel symfony 2

这是我第一次使用symfony 2。对于数据库集成,我正在考虑使用Propel,因为我的学说和注释对我来说似乎真的很困难。但在我看来,要进行查询,您必须使用推动自己的函数。我用过编码点火器。在代码点火器中,我曾经发送查询字符串,它曾经向我发送数据。在推进symfony 2中是否有类似的东西?喜欢-

$query = 'select * from table where column1 natural join column2';
$this->db->query($query);

你应该看看 sf2 的文档:
http://symfony.com/doc/current/book/propel.html

如果要使用原始 SQL:

$em = $this->getDoctrine()->getEntityManager();
$connection = $em->getConnection();
$statement = $connection->prepare("SELECT something FROM somethingelse");
$statement->execute();
$results = $statement->fetchAll();

或"推进方式":

$connection = Propel::getConnection();
$query = 'SELECT MAX(?) AS max FROM ?';
$statement = $connection->prepareStatement($query);
$statement->setString(1, ArticlePeer::CREATED_AT);
$statement->setString(2, ArticlePeer::TABLE_NAME);
$resultset = $statement->executeQuery();
$resultset->next();
$max = $resultset->getInt('max');