简体   繁体   English

带有propel symfony 2的自定义查询

[英]custom query with propel symfony 2

This is my first time using symfony 2. For database integration i am thinking of using propel as I doctrine and annotations seems really difficult for me. 这是我第一次使用symfony2。对于数据库集成,我正在考虑使用propel作为我的学说,而注释对我来说似乎真的很困难。 But it seems to me that to make a query you have to use propels own functions. 但是在我看来,要进行查询,您必须使用propels自己的函数。 I have used codeigniter. 我用了codeigniter。 In codeigniter I used to send query string and it used to send me data. 在codeigniter中,我用来发送查询字符串,它用来向我发送数据。 Is there something similar in propel symfony 2? 推进symfony 2中有类似的东西吗? Like - 喜欢 -

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

You should look at docs of sf2: 您应该查看sf2的文档:
http://symfony.com/doc/current/book/propel.html http://symfony.com/doc/current/book/propel.html

If you want to use raw SQL: 如果要使用原始SQL:

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

Or "propel way": 或“推进方式”:

$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');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM