has any one a better solution for me for that code:
<?php
try {
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->beginTransaction();
$dbh->exec("LOCK TABLES test2 WRITE");
$row = $dbh->query('SELECT * from test2 WHERE c > 0 LIMIT 1');
$stmt = $dbh->prepare("UPDATE test2 SET c=c-1 WHERE a=:a and c>0");
$stmt->bindParam(':a', $row['a']);
$stmt->execute();
/**
...
....
.....
**/
$dbh->exec("UNLOCK TABLES");
$dbh->commit();
$dbh = null;
} catch (PDOException $e) {
error_log("Error!: " . $e->getMessage() . "\n", 3, "./my-errors.log");
exit();
}
When i get simultaneously connections to that script, every connection should have his own row from the table test2 (field A).
Thanks for your ideas :-)