Файл: pesn_voini/peseni_vojni/instalscript/engine/cron/energy.php
Строк: 49
<?php
//
try{
$BaseConnect = new PDO("mysql:host=localhost;dbname=client616_anjy",'client616_anjy','P2j7G9d6');
}
catch(PDOException $e){
die('Нет соединения с базой данных!');
}
$BaseConnect->exec("set names utf8");
//
//Для обычного запроса
function cnt($sql, $params = array()) {
global $BaseConnect;
$stmt = $BaseConnect -> prepare($sql);
$stmt -> execute($params);
$stmt = $stmt->rowCount();
return $stmt;
}
//
//Работаем с базой данных
function qry($sql, $params = array()) {
global $BaseConnect;
$stmt = $BaseConnect -> prepare($sql);
$stmt -> execute($params);
return $stmt;
}
//
//Для вывода ассоциотивного массива
function fch($sql, $params = array()) {
global $BaseConnect;
$stmt = $BaseConnect -> prepare($sql);
$stmt -> execute($params);
$stmt = $stmt->fetch();
return $stmt;
}
//
$user_q = $BaseConnect->query("SELECT * FROM `users` WHERE `energy` < `energy_max`");
//
while($user = $user_q->fetch(PDO::FETCH_ASSOC)){
//
$energy = $user['energy_max']*2/100;
//
if($energy >= $user['energy_max']){
qry("UPDATE `users` SET `energy` = ? WHERE `id` = ? LIMIT 1", array($user['energy_max'],$user['id']));
}else{
qry("UPDATE `users` SET `energy` = `energy` + ? WHERE `id` = ? LIMIT 1", array($energy,$user['id']));
}
//
}
?>