小编ara*_*mir的帖子

ZF2插入多行

我想知道是否有仅使用一个$ SQL对象(而不是使用查询(SQL命令)方法)来插入在ZF2多行的方式.

我试过这样的东西,但它不起作用:

public function setAgentProjectLink( $IDProject , $IDsAgents )
{
    $values = array () ;
    foreach ( $IDsAgents as $IDAgent):
    {
        $values[] = array ( 'id_agent' => $IDAgent , 'id_projet' => $IDProject) ;
    } endforeach ;

    $sql = new Sql( $this->tableGateway->adapter ) ;
    $insert = $sql->insert() ;

    $insert -> into ( $this->tableGateway->getTable() )
            -> values ( $values ) ;

    $statement = $sql->prepareStatementForSqlObject($insert);
    $result = $statement->execute();
}
Run Code Online (Sandbox Code Playgroud)

尝试在具有两列的数据库中插入值(id_agent, id_projet)

sql zend-framework2

7
推荐指数
1
解决办法
5145
查看次数

标签 统计

sql ×1

zend-framework2 ×1