How can Zend_Db be used to update multiple tables using joins?
Is there an equivalent to the following SQ开发者_如何学CL using the Zend_Db modules?
UPDATE items,month SET items.price=month.price
WHERE items.id=month.id;
The mysql manual states
... multiple-table UPDATE statements can use any type of join permitted in SELECT statements, such as LEFT JOIN.
You can always execute a query string.
$db->query("UPDATE items,month SET items.price=month.price WHERE items.id=month.id")
Disclaimer: I haven't tested it.
With MySQL, you can use JOIN
(left, right or inner) in UPDATE
the same way as you would in a SELECT
statement.
Your code would look like this:
$sql = <<<END
UPDATE table1
INNER JOIN table2 ON table1.id = table2.other_id
SET table1.newvalue = 'value'
WHERE table1.id = 99
AND table2.other_value = 'value'
END;
$result = $db->query($sql);
The $result
variable will contain an object related to your adapter type. I use PDO_MYSQL so I ended up with a Zend_Db_Statement_Pdo
object.
精彩评论