简体   繁体   中英

PHP script running on cron job - email alert

I'm building a Joomla site, but I'm stuck at something, wondering if you guys could kindly help me out.

I'm trying to get an alerting system working.

I essentially need to create a cron job that runs a PHP script every 10 minutes. This PHP script should basically do a select query on the database, and if a particular field has a specific value, then open a website.

So, this is what I have now:

$result = mysql_connect(localhost, myusername, mypassword);
mysql_select_db("database_name");
$result = mysql_query( "SELECT from_table");

The table name is: comments. The field name is: published.

So what I would ideally need, is that if the value of published = 0, then the php script should open this URL, which will send me an sms message https://www.voipbuster.com/myaccount/sendsms.php?username=xx&password=xx&from=xx&to=xx&text=Alert

And if there is any other value, I don't want it to do anything.

So, anytime there is value 0 I receive a text message.

Hope this makes sense, thanks for your immense patience reading.

Switch to PDO (or MySQLi). The API you're using is deprecated.

(based on nothing - this is a guess)

$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
$sql = 'SELECT published FROM sometable';
$stmt = $dbh->prepare($sql);
$stmt->execute();
$stmt->setAttribute(PDO::FETCH_ASSOC);
$row = $stmt->fetch();

if( $row['published'] == 0 )
{
    $ch = curl_init(" https://www.voipbuster.com/myaccount/sendsms.php?username=xx&password=xx&from=xx&to=xx&text=Alert");

    curl_exec($ch);
    curl_close($ch);

}

Get Andrew Eddie's script for cron plugins and run that. Then write a plugin in the cron group that sends your email. https://github.com/eddieajau/jc-kodaly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM