Dirk Posted February 15, 2006 Posted February 15, 2006 Hello, I would like to write a script that does a database query and emails me the results. Does anyone have something similar working on TCH that I can adapt? Especially the email part is very dependent on host setup (scripted mail is probably restrictive, for example "mail" command in shell script does not seem to work). I could probably do the DB part myself. Thanks Dirk Quote
TCH-JimE Posted February 15, 2006 Posted February 15, 2006 Hello, I use a cronjob to call a php page which empties a table for me every so often. It emails me the results of it being cleared, so i would suggest something like that Jimuni Quote
Dirk Posted February 16, 2006 Author Posted February 16, 2006 Bruce... doh! yes, seems obvious. /usr/sbin/sendmail is that the path to use? Are there any restrictions? I only want mail delivered locally to my own mail account, so no spamming or similar Jimuni, would you mind sharing that php with me? Would be very helpful. You can of course take out things you don't want to share, just would like to see how to query the DB and all that. Regards Dirk Quote
TCH-Bruce Posted February 16, 2006 Posted February 16, 2006 You are correct. /usr/sbin/sendmail Quote
TCH-JimE Posted February 16, 2006 Posted February 16, 2006 (edited) Hello, The cronjob: >php -q /home/XXXUSERNAMEXXXX/public_html/cronjob.php (obviously put your correct username in above where its XXXUSERNAMEXXX} and also its set to do this every 12 hours. The CPANEL allows you to mail the output to email address which saves having to figure out the email problem! This is the cronjob it calls, a php file. ><html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php /* Start of PHP3 Script */ /* Data of SQL-server */ /* $server= "server5.totalchoicehosting.com"; Address of my server */ $dbhost = 'localhost' /* Use Localhost */ $user= "XXXXXX"; /* Database username */ $password= "XXXXXX"; /* Database Password */ $database= "XXXXXX"; /* name of database */ $table= "phpBB_sessions"; /* Name of table */ /* Accessing SQL-Server and emptying table */ MYSQL_CONNECT($dbhost, $user, $password) or die ( "<H3>Server unreachable</H3>"); MYSQL_SELECT_DB($database) or die ( "<H3>Database non existent</H3>"); $result=MYSQL_QUERY( "Empty TABLE $table"); echo "<H1>Table was Emptied successfully</H1>"; /* Close SQL-Connection */ MYSQL_CLOSE(); ?> </body> </html> Hope this helps! Jimuni Edited February 16, 2006 by Jimuni Quote
Dirk Posted February 17, 2006 Author Posted February 17, 2006 This is very useful, esp. hint about emailing output via cron. Cheers Dirk Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.