$online = $db->query("SELECT * FROM `online` WHERE `ip` = '$_SERVER[REMOTE_ADDR]'")->fetch(PDO::FETCH_NUM); |
if(!$online[0]) $db->exec("INSERT INTO `online` (`ua`,`ip`,`time`) VALUES ('$_SERVER[HTTP_USER_AGENT]','$_SERVER[REMOTE_ADDR]','$_SERVER[REQUEST_TIME]');"); |
else $db->exec("UPDATE `online` SET `time` = '$_SERVER[REQUEST_TIME]' WHERE `id` = '$online[0]'"); |
$online = NULL; |
$db->exec("DELETE FROM `online` WHERE '$_SERVER[REQUEST_TIME]' - `time` > 360"); |
try |
{ |
$dbh -> setAttribute ( PDO :: ATTR_ERRMODE , PDO :: ERRMODE_EXCEPTION ); |
$dbh -> beginTransaction (); |
$dbh -> exec ( "insert into staff (id, first, last) values (23, 'Joe', 'Bloggs')" ); |
$dbh -> exec ( "insert into salarychange (id, amount, changedate) values (23, 50000, NOW())" ); |
$dbh -> commit (); |
} |
catch ( Exception $e ) |
{ |
$dbh -> rollBack (); |
echo "Шеф! Фсё пропало : " . $e -> getMessage (); |
} |
$online = $db->query('SELECT * FROM `online` WHERE `ip` = "'.$_SERVER['REMOTE_ADDR'].'"')->fetch(PDO::FETCH_NUM); |
$db->beginTransaction(); |
if($online[0]){ |
$db->exec('UPDATE `online` SET `time` = "'.$_SERVER['REQUEST_TIME'].'" WHERE `id` = "'.$online[0].'"'); |
} else { |
$zapis = $db->prepare("INSERT INTO `online` (`ua`,`ip`,`time`) VALUES (?,?,?);"); |
$zapis->execute(array($_SERVER['HTTP_USER_AGENT'],$_SERVER['REMOTE_ADDR'],$_SERVER['REQUEST_TIME'])); |
} |
$db->exec('DELETE FROM `online` WHERE "'.$_SERVER['REQUEST_TIME'].'" - `time` > 360'); |
$db->commit(); |
$online = NULL; |