MyBB Community Forums

Full Version: Schreduled task problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
i'm using MyBB: 1.4.13 and i'm trying to create the fallowing custom task
<?php
/**
 * MyBB 1.4
 * Copyright © 2008 MyBB Group, All Rights Reserved
 *
 * Website: http://www.mybboard.net
 * License: http://www.mybboard.net/about/license
 *
 * $Id: inactiveaccounts.php 4304  2010-06-19 23:11:56Z ADN $
 */

function task_inactiveaccounts($task)
{
	global $db, $lang;
	
	// Delete old inactive accounts
	$db->delete_query("`ac_validate` WHERE DATE_SUB(CURDATE(),INTERVAL 3 DAY) > joindate;");

	add_task_log($task, $lang->task_inactiveaccounts_ran);
}

?>

ac_validate it's in the same database as MyBB database but i can't run the query since MyBB ads the TABLE_PREFIX automatically.

Any ideeas how can I solve this?

The exact error message i'm getting, so you can make an ideea.
SQL Error:
    1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE DATE_SUB(CURDATE(),INTERVAL 3 DAY) > joindate' at line 2
Query:
    DELETE FROM bb_`ac_validate` WHERE DATE_SUB(CURDATE(),INTERVAL 3 DAY) > joindate; 

Thank you for your time.
The delete query function has specific parameters.

$db->delete_query($table, $where);

However these database functions (simple_select, insert_query, update_query, delete_query etc) will only work for MyBB tables, because of the prefix, they're not general functions for running queries. You'd want this:

$db->query("DELETE FROM ac_validate WHERE DATE_SUB(CURDATE(),INTERVAL 3 DAY) > joindate");