<?php
require_once('vk.php');
$vk = new VK();
$peer_id1 = $vk->data['object']['peer_id'];
$peer_id = $vk->data['object']['peer_id'];
$text = $vk->data['object']['text'];
$user_link_b = $vk->data['object']['action']['type'];
$user_id = $vk->data['object']['from_id'];
$member_id = $vk->data['object']['action']['member_id'];
$chat_id = '2';
// Параметры для подключения
$db_host = "localhost";
$db_user = "123"; // Логин БД
$db_password = "pas"; // Пароль БД
$db_base = 'bd'; // Имя БД
$db_table = "table"; // Имя Таблицы БД
// Подключение к базе данных
$mysqli = new mysqli($db_host,$db_user,$db_password,$db_base);
// Если есть ошибка соединения, выводим её и убиваем подключение
if ($mysqli->connect_error) {
die('Ошибка : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}
if ($vk->data['type'] == 'message_new')
{
// Добавление
$time_s = date("U");
$result = $mysqli->query("INSERT INTO ".$db_table." (user_id,time) VALUES ('$user_id','$time_s')");
// Id
$lim = $mysqli->query("SELECT MAX(Id) FROM table");
$row = $lim->fetch_row();
if(($row[0] % 3) == 0)
{
// time и user_id
$time111 =$mysqli->query("SELECT time FROM table ORDER BY id LIMIT 1 OFFSET 0"); // time - 1
$time11 = $time111->fetch_row();
$time1 = $time11[0];
$time222 =$mysqli->query("SELECT time FROM table ORDER BY id LIMIT 1 OFFSET 1"); // time - 2
$time2 = $time222->fetch_row();
$time2 = $time22[0];
$time333 =$mysqli->query("SELECT time FROM table ORDER BY id LIMIT 2 OFFSET 2"); // time - 3
$time3 = $time333->fetch_row();
$time3 = $time33[0];
$user111 =$mysqli->query("SELECT user_id FROM table ORDER BY id LIMIT 1 OFFSET 0"); // user_id - 1
$user11 = $user111->fetch_row();
$user1 = $user11[0];
$user222 =$mysqli->query("SELECT user_id FROM table ORDER BY id LIMIT 1 OFFSET 1"); // user_id - 2
$user22 = $user222->fetch_row();
$user2 = $user22[0];
$user333 =$mysqli->query("SELECT user_id FROM table ORDER BY id LIMIT 2 OFFSET 2"); // user_id - 3
$user33 = $user333->fetch_row();
$user3 = $user33[0];
// Проверка
if((($time3 - 2) >= $time1) and (($time3 - 2) >= $time2) and ($user3 == $user1) and ($user3 == $user2))
{
// Исключение пользователя
$vk->send1($chat_id, $user_id, $member_id);
}
// Удаляет все записи из таблицы
$mysqli->query("truncate table table");
}
}
select user_id, time ftom myTable where time > now() - interval 2 second
select user_id ftom myTable
where time > now() - interval 2 second
group by user_id
having COUNT(*) > 1