View difference between Paste ID: dftPieSa and GraVPrBJ
SHOW: | | - or go back to the newest paste.
1
<?php
2
$sleep = 0;
3
if (isset($_GET['sleep'])) {
4
    $sleep = $_GET['sleep'];
5
}
6
7-
$pdo = new PDO('mysql:host=localhost;dbname=test', 'root', 'vertrigo');
7+
$pdo = new PDO('mysql:host=localhost;dbname=test', 'root', 'xxxxxx');
8
$pdo->beginTransaction();
9
$data = $pdo->query('SELECT counter FROM foo WHERE id=1 FOR UPDATE', PDO::FETCH_ASSOC);
10
11
foreach ($data as $row) {
12
    $c = $row['counter'];
13
}
14
++$c;
15
16
sleep($sleep);
17
$state = $pdo->query("UPDATE foo SET counter = $c WHERE id=1");
18
$res = NULL;
19
if ($state) {
20
    $res = $state->execute();
21
}
22
$pdo->commit();
23
24
echo $c;
25
var_dump($res);
26
var_dump($state);
27
exit;