Je ne vois pas une véritable méthode Zend DB pour verrouiller les tables, mais peut-être faire ceci:
//Lock Table
$sql = "LOCK TABLE page WRITE";
$db->fetchRow($sql);
//Get your data
$sql = "SELECT * FROM page WHERE col='value'";
$result = $db->fetchAll($sql);
//Make the insert
$data = array('col1' => 'val1', 'col2' => 'val2');
$db->insert('page', $data);
//Unlock tables
$sql = "UNLOCK TABLES";
$db->fetchRow($sql);
Probablement pas la meilleure solution et il est non testé. Mais ça pourrait marcher pour toi.
MISE À JOUR: J'ai trouvé une meilleure solution pour vous. Utilisez transactions:
// Start a transaction explicitly.
$db->beginTransaction();
try {
//Get your data
$sql = "SELECT * FROM page WHERE col='value'";
$result = $db->fetchAll($sql);
//Make the insert
$data = array('col1' => 'val1', 'col2' => 'val2');
$db->insert('page', $data);
// If all succeed, commit the transaction and all changes
// are committed at once.
$db->commit();
} catch (Exception $e) {
// If any of the queries failed and threw an exception,
// we want to roll back the whole transaction, reversing
// changes made in the transaction, even those that succeeded.
// Thus all changes are committed together, or none are.
$db->rollBack();
echo $e->getMessage();
}
J'ai récemment rencontré le même problème et les transactions ont beaucoup travaillé. Certainement le chemin à parcourir.
je suppose que je vais devoir le faire de cette façon .. Merci pour la réponse. – deepanshuyadav