Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Kritischer PHP/MySQL-Abschnitt

Noch eine Lösung nur der Vollständigkeit halber:

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);
}

MySQL GET_LOCK()-Dokumentation