A
A
Alexander2015-08-06 20:54:21
MySQL
Alexander, 2015-08-06 20:54:21

Have I written the stored procedure code correctly?

DELIMITER //

BEGIN

SET @email = (SELECT email FROM accounts WHERE id = uid LIMIT 1);
SET @rdt = (SELECT regDT FROM accounts WHERE id = uid LIMIT 1);
SET @now = NOW();

IF @email IS NULL AND @now > DATE_ADD(@rdt, INTERVAL 7 DAY) THEN 
UPDATE accounts SET blocked = 1 WHERE id = uid LIMIT 1;
END IF;

END//

The procedure receives the user ID [uid] as input, then it receives the registration date and email address as variables. mail. Next, it checks if the user has entered his email and how many days have passed since the registration date. If the mail is not entered and more than a week has passed since the date of registration, then the account is blocked.
accounts table:
CREATE TABLE IF NOT EXISTS `accounts` (
  `id` bigint(20) NOT NULL COMMENT 'Идентификатор пользователя',
  `login` tinytext NOT NULL COMMENT 'Логин',
  `pass` tinytext NOT NULL COMMENT 'Пароль',
  `email` tinytext COMMENT 'Почта',
  `regDT` datetime NOT NULL COMMENT 'Дата и время регистрации',
  `regIP` varchar(15) NOT NULL DEFAULT '0.0.0.0' COMMENT 'Регистрационный IP',
  `blocked` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Заблокирован?'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Аккаунты';

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2015-08-06
@zkelo

UPDATE `accounts` 
    SET `blocked` = 1
    WHERE `email` IS NULL 
        AND `regDT` < NOW() - INTERVAL 7 DAY
        AND `id` = :uid

Well, or remove the last line if you need to block all such records at once.

D
Dmitry Kovalsky, 2015-08-06
@dmitryKovalskiy

Normal storage. but you can try to do an UPDATE with one request

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question