duanduo7400 2015-06-11 11:41
浏览 41
已采纳

MySQLi事件在一定时间后删除行

I want users on my page to verify thier accounts (email) in one day. If a user isn't verified yet the datetime (date) is set to something like 0000-03-23 15:45:56 (the year is 0000 - I know that this causes problems in new years eve).

Event: (every hour)

DELETE FROM users WHERE SUBSTR(date, 0, 4)='0000' AND DAY(TIMEDIFF(NOW(), date)) >= 1

The event isn't working so i've created this test query:

$resultOne = $mysqli->query("SHOW COLUMNS FROM users WHERE SUBSTR(date, 0, 4)='0000'")or die($mysqli->error);
$resultTwo = $mysqli->query("SHOW COLUMNS FROM users WHERE DAY(TIMEDIFF(NOW(), date)) >= 1")or die($mysqli->error);

Now i'm getting this error message:

Unknown column 'date' in 'where clause'

Questions:

  • Why isn't it working?
  • Which better ways to verify users do you recomment?

Thank you! - Minding

  • 写回答

1条回答 默认 最新

  • drfu80954 2015-06-11 12:37
    关注

    Ok, there where two problems here:

    First: test query

    The "SHOW COLUMNS" didn't accept my where clause, but "SELECT *" did.

    Second: SUBSTR()

    I don't know exectly why, but the MySQLi SUBSTR has to be:

    SUBSTR(date, 1, 4)='0000'
    

    Not like in PHP:

    substr($user['date'], 0, 4) === '0000'
    

    One last problem:

    New users are deleted nearly instantly (every hour -> test: every minute) and not after 1 day as they should.

    EDIT:

    I just want to share my final event code, in case somebody needs it:

    DELETE FROM users WHERE SUBSTR(date, 1, 4)='0000' AND HOUR(TIMEDIFF(NOW(), CONCAT(SUBSTR(NOW(), 1, 5), SUBSTR(date, 5)))) >= 24
    

    Thank you all for your comments! - Minding

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 求给定范围的全体素数p的(p-2)的连乘积
  • ¥15 VFP如何使用阿里TTS实现文字转语音?
  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页