Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $sleep = 0;
- if (isset($_GET['sleep'])) {
- $sleep = $_GET['sleep'];
- }
- $pdo = new PDO('mysql:host=localhost;dbname=test', 'root', 'xxxxxx');
- $pdo->beginTransaction();
- $data = $pdo->query('SELECT counter FROM foo WHERE id=1 FOR UPDATE', PDO::FETCH_ASSOC);
- foreach ($data as $row) {
- $c = $row['counter'];
- }
- ++$c;
- sleep($sleep);
- $state = $pdo->query("UPDATE foo SET counter = $c WHERE id=1");
- $res = NULL;
- if ($state) {
- $res = $state->execute();
- }
- $pdo->commit();
- echo $c;
- var_dump($res);
- var_dump($state);
- exit;
Advertisement
Add Comment
Please, Sign In to add comment