如何使用zend 2

时间:2017-07-14 12:24:45

标签: zend-framework zend-framework2 zend-db zend-db-table

我正在尝试使用zend 2使用单个查询插入多个数据。以下是代码的参考。它没有抛出任何错误,但数据没有插入。我从控制器调用“mapOffers”,我将传递索引数组“$ assigned_b”。请帮助我。

namespace Offers\Model;
   use Zend\Db\Adapter\Adapter;
   use Zend\Db\TableGateway\AbstractTableGateway;
   use Zend\Db\Sql\Sql;
   use Zend\Db\Sql\Select;
   use Zend\Db\Sql\Where;
use Zend\Db\Sql\Insert;
use Utility\Utility;
class OffersTable extends AbstractTableGateway {

    protected $table = 'offers';
    protected $joinTable = 'organization';
    protected $b_offer = 'b_offers';
    protected $sql_object,$select_object;


    public function __construct(Adapter $adapter) {
        $this->adapter = $adapter;
    }


    public function mapOffers($assigned_b,$offer_id){

        $sql = new Sql( $this->adapter );
        $delete = $sql->delete($this->beacon_offer)->where("offer_id = $offer_id");
        $deleteString = $sql->getSqlStringForSqlObject($delete);

        $query = 'INSERT INTO '.$this->offers . ' (`offer_id`, `b_id`) VALUES ';
        $queryVals = array();

         foreach ($assigned_b as $_bid) {
              if($_bid){
                $queryVals[] = "(".$offer_id.",".$_bid.")";  
              }
         }

         $stmt = $this->adapter->query($query . implode(',', $queryVals));

    }




}

1 个答案:

答案 0 :(得分:0)

你需要调用execute函数。它必须看起来像那样(来自我自己的项目的例子)

$this->adapter->query($query)->execute();