Hi there,
I wrote a PHP script that I would like to launch everyday with a cron job. It should connect to my database with PDO and get some information from it, but what I get is an error (more details below) even though the same code works well when launched from a browser.
Here's my cron job:
Here's the beginning of my delete.php script:
And this is the error I get in etc/deletelog.txt:
As I said, the script works well when launched from a browser but not from a cron job. Am I missing something?
I wrote a PHP script that I would like to launch everyday with a cron job. It should connect to my database with PDO and get some information from it, but what I get is an error (more details below) even though the same code works well when launched from a browser.
Here's my cron job:
Code:
0 0 * * * /usr/bin/php -q /home/osusigna/www/delete.php >> /home/osusigna/etc/deletelog.txt 2>&1
Code:
// I heard absolute paths would be better than relative paths for a cron job, but no luck
if ($_SERVER['HTTP_HOST'] == 'localhost') $wwwPath = './';
else if ($_SERVER['HTTP_HOST'] == 'osusignature.x10.mx') $wwwPath = '/home/osusigna/www/';
// This file defines variables about database connection: DB name, user and password.
include($wwwPath.'resources/globalVariables.php');
// Create connection to database
try {
$bdd = new PDO('mysql:host=localhost;dbname='.$dbName, $dbUser, $dbPassword);
}
catch(Exception $e) {
die('Error: '.$e->getMessage());
}
[...]
And this is the error I get in etc/deletelog.txt:
Code:
Error: SQLSTATE[28000] [1045] Access denied for user 'osusigna'@'localhost' (using password: NO)
Last edited: