Reputation: 866
I want t make a zend update query.
I was looking at zend documentation but I didn't see any example like the one I want.
The question its if may someone could help me with the query.
I want to make the next query:
Update cars set active = 0
Where id in (SELECT idCar FROM UserCars Where idUser=3)
Upvotes: 0
Views: 4708
Reputation: 106385
Perhaps more Zendy way:
$idUser = 3;
$sub_select
= $db->select()
->from('UserCars', array('id'))
->where('idUser = ?', $idUser);
$updated_rows
= $db->update('cars',
array('active' => 0),
"id IN ($sub_select)"
);
Upvotes: 3
Reputation: 12830
Simplest way to run any complex query. There can be some better ways to do same.
$sql = "Update cars set active = 0
Where id in (SELECT idCar FROM UserCars Where idUser=3)";
$query = $this->getDbTable()->getAdapter()->query($sql, $data);
$query->execute();
Try this too
$data = array { 'active' = '0' };
$where = "id in (SELECT idCar FROM UserCars Where idUser=3)";
$db->update($data, $where);
Upvotes: 3