Cron job using PHP

Hi I have the following php script
<?php

$dbHost             = 'localhost';
$dbUsername       = 'rafale3_rcleon';
$dbPassword       = 'SXX';
$dbName            = 'rafale3_TCBPro';

$Connection = @mysql_connect(localhost, rafale3_rcleon, SXX) or die ("Unable to connect to MySQL RCL");

$SelectDB = @mysql_select_db(rafale3_TCBPro, $Connection) or die ("Unable to select database");

$Today = date("Y-m-d");
$dateOneYearAdded = strtotime(date("Y-m-d", strtotime($Today)) . " -1 year");
$OneYearFromContractDate = date('Y-m-d', $dateOneYearAdded);
$SQL = "
  UPDATE PRO_CD SET
  Status = 'I'
  WHERE ContractDate < '$OneYearFromContractDate'
  AND Paid = 'Y'
";

mysql_query($SQL) or die('Error, query failed');

?>

my cron command is: /home/rafale3/public_html/pro/admin/proc/UpdateStatusOfPro.php

I keep getting the following errors:home/rafale3/public_html/pro/admin/proc/UpdateStatusOfPro.php: line 2: syntax error near unexpected token `localhost,'
/home/rafale3/public_html/pro/admin/proc/UpdateStatusOfPro.php: line 2: `mysql_connect(localhost, rafale3_rcleon, SXX) or die ("Unable to connect to MySQL RCL");'


Any help will be appriciated

Thanks

Rafael
rcleonAsked:
Who is Participating?
 
Ray PaseurConnect With a Mentor Commented:
You might also want to put this into a cron job and run it.  It will email you the phpinfo() that the cron job sees.  This is likely to be different from what web scripts see.  Compare the paths and variables closely.
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ob_start();
phpinfo();
$msg = ob_get_clean();
mail('You@Your.org', 'CRON OUTPUT', $msg);

Open in new window

0
 
zicevaCommented:
add

#!/usr/bin/php

on the first line

(if the php binary is not located in the /usr/bin/ folder you can type "whereis php" in a terminal to find out where is it located)
0
 
rcleonAuthor Commented:
Thanks

here is the new file:
<?php
#!/usr/bin/php
require('../../DBC.php');
require('../../TBL.php');


$Today = date("Y-m-d");
$dateOneYearAdded = strtotime(date("Y-m-d", strtotime($Today)) . " -1 year");
$OneYearFromContractDate = date('Y-m-d', $dateOneYearAdded);

$SQL = "
  UPDATE $Table1 SET
  Status = 'I'
  WHERE ContractDate < '$OneYearFromContractDate'
  AND Paid = 'Y'
";

mysql_query($SQL) or die('Error, query failed');
?>

Here is the new error:

/bin/sh: home/rafale3/public_html/pro/admin/proc/UpdateStatusOfPro.php: No such file or directory
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
gr8gonzoConsultantCommented:
mysql_connect(localhost, rafale3_rcleon, SXX should probably be:

mysql_connect($dbHost, $dbUsername, $dbPassword) or die....
0
 
zicevaCommented:
nope... on the first line, BEFORE the tag

#!/usr/bin/php
<?
....
0
 
rcleonAuthor Commented:
Thanks

I will try next
0
 
Sandeep KothariProject LeadCommented:
why the strings passed in the function are not in single or double quotes ...
what I mean for the below lines in your code... put stings like localhost, rafale3_rcleon, SXX in single or double quotes....
$Connection = @mysql_connect(localhost, rafale3_rcleon, SXX) or die ("Unable to connect to MySQL RCL");

$SelectDB = @mysql_select_db(rafale3_TCBPro, $Connection) or die ("Unable to select database");

0
 
Ray PaseurCommented:
Regarding this:
$Connection = @mysql_connect(localhost, rafale3_rcleon, SXX) or die ("Unable to connect to MySQL RCL");

PHP will first try to interpret the unquoted strings as defined constants.  It will fail, and PHP will issue a notice but you may not see the notice unless you have raised error_reporting(E_ALL) and that is something you always want to do.

After the failure and the notice. PHP will next try to interpret the unquoted strings as single-quoted, literal strings.

Man page here:
http://php.net/manual/en/language.types.string.php

Best regards, ~Ray
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.