View Full Version : Setting up a SQL Query to run every day
canesoverhere.com
12-23-2006, 11:24 PM
I'm new to the hostmonster interface (Cpanel), so forgive my newbiness. If I want to run a SQL query at 3am every day to clean up the database in my phpBB forum, how would I go about that? Is that possible in a crontab? If so, any help with syntax would be appreciated.
Thanks in advance.
sjlplat
12-24-2006, 12:02 AM
Cron is used to run scripts at specified intervals. If you have a specific script you want to use for your database functions, it could be handled by Cron.
phpBB also has a pruning option to handle topics with no replies. This can be set to operate at a specified interval of days.
canesoverhere.com
12-24-2006, 10:53 AM
Cron is used to run scripts at specified intervals. If you have a specific script you want to use for your database functions, it could be handled by Cron.Thanks...what I'm mainly interested in is just executing a delete SQL query to remove users who I believe to be spambots. So, what I'm looking for is syntax/directions on how to run something like the following, every day, from my phpbb forum database:
delete from 'phpbb_users' where 'phpbb_users'.'user_from' = 'China';
I just don't know how to get the crontab to execute the query, recognize that I want to run that on the phpbb_forum database, etc.
McCoy
12-24-2006, 12:12 PM
You can create a PHP script which execute those SQL queries and call that script periodically from cron.
Cron can only execute files directly, not SQL queries or stuff like that.
sjlplat
12-25-2006, 07:35 AM
You can create a PHP script which execute those SQL queries and call that script periodically from cron.
Cron can only execute files directly, not SQL queries or stuff like that.
X2 - You'll have to use a PHP script to perform the database function, and use Cron to execute the PHP script at a specified interval.
canesoverhere.com
12-25-2006, 05:23 PM
OK, thanks again for the insight. Anyone willing to tell me how to create a PHP script?
sjlplat
12-25-2006, 08:37 PM
I'm no PHP coder. The first place I look is http://www.hotscripts.com for anything that might have already been developed to fit my needs. If you're willing to spend a little money, you might consider making a post at http://www.getafreelancer.com
bensranchtw
01-01-2007, 08:33 PM
I'm no PHP coder. The first place I look is http://www.hotscripts.com for anything that might have already been developed to fit my needs. If you're willing to spend a little money, you might consider making a post at http://www.getafreelancer.com
Or just check out google. SQL Queries are very simple to do, especially mysql.
-T
<?php
$db = mysql_connect("localhost", "username", "password");
mysql_select_db("phpbb_forum",$db);
$query = "DELETE FROM phpbb_users WHERE user_from = 'China'";
mysql_query($query) or die(mysql_error());
mysql_close();
?>
Something like that should work. Save it as a .php file and have cron run it. Make sure to change "username", "password" and also "phpbb_forum" if not correct, to their correct values.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.