Mysql
 sql >> Base de données >  >> RDS >> Mysql

Section critique PHP/MySQL

Une autre solution juste pour être complet :

private function getLock() {
    $lock = $this->pdo->query("SELECT GET_LOCK('my_lock_name', 5)")->fetchColumn();

    if ($lock != "1")
        throw new RuntimeException("Lock was not gained: " . $lock);
}

private function releaseLock() {
    $releaseLock = $this->pdo->query("SELECT RELEASE_LOCK('my_lock_name')")->fetchColumn();

    if ($releaseLock != "1")
        throw new RuntimeException("Lock not properly released " . $releaseLock);
}

Documentation MySQL GET_LOCK()