How to run raw SQL Query with Zend Framework 2

后端 未结 4 1638
离开以前
离开以前 2020-12-30 04:14

Is there a way to execute a SQL String as a query in Zend Framework 2?

I have a string like that:

$sql = \"SELECT * FROM testTable WHERE myColumn = 5         


        
4条回答
  •  余生分开走
    2020-12-30 05:00

    If you are using tableGateway, you can run your raw SQL query using this statement,

    $this->tableGateway->getAdapter()->driver->getConnection()->execute($sql);
    

    where $sql pertains to your raw query. This can be useful for queries that do not have native ZF2 counterpart like TRUNCATE / INSERT SELECT statements.

提交回复
热议问题