【问题标题】:custom query with propel symfony 2使用推进 symfony 2 的自定义查询
【发布时间】:2013-11-14 22:53:10
【问题描述】:

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

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

【问题讨论】:

    标签: php sql codeigniter symfony propel


    【解决方案1】:

    你应该看看 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');
    

    【讨论】:

    • 非常感谢您的帮助。但是你为什么使用 getDoctrine?而且我在你给我的链接中找不到任何关于它的信息:(
    • 您可以使用参数化来指定列名或表名吗?我似乎记得读过它会遇到麻烦,而且它明确地仅用于值。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-20
    • 1970-01-01
    相关资源
    最近更新 更多