Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

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 :pissed:

 

 

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

Posted (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 by Jimuni

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...