Developer
Developer

Reputation: 3

Update query in zend framework 2

I am using adapter in zend framework 2. My code is for mysql update query which is not working, can any one suggest me. Array result is ok but its not display in query. Just shows update tablename set.

I have tried all suggestions of SO and also from Google, but I am failed to solve that problem.

Code is here:

public function updatebhkdetail($bhkupdate)
{
    $WHERE = 'project_id='.$bhkupdate['project_id'];
    $sql = new Sql($this->adapter);
    $update1bhk = $sql->update('tablename', array($bhkupdate), $WHERE);
    $statementUpdate = $sql->getSqlStringForSqlObject($update1bhk);
    $sectorName = $this->adapter->query($statementUpdate,
                         \Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE);
}

Upvotes: 0

Views: 4063

Answers (1)

Pedro
Pedro

Reputation: 163

I'm not to familiar with getSqlStringForSqlObject. But this should work:

$sql    = new Sql( $this->adapter );
$update = $sql->update();
$update->table( <yourTableName> );
$update->set( $keyValues );
$update->where( array( 'project_id' => $bhkupdate['project_id'] ) );

$statement  = $sql->prepareStatementForSqlObject( $update );
$results    = $statement->execute();

Upvotes: 3

Related Questions