MySQL Permissions for CRON job

1.1k Views Asked by At

I have written a PHP script to be executed by CRON on a daily basis to clean files and remove old database entries..

The script has no problems being run, so I know its not a CRON issue.

The problem is that I get the following error:

Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[42000]: Syntax error or access violation: 1142 SELECT command denied to user 'username'@'localhost' for table 'users' in /cron_removeOld.php on line 35

I am using the same DB credentials for the backend admin users, so I know they have SELECT privileges. I'm wondering if it has something to do with the script being run outside of the webserver?

Any help would be greatly appreciated!

Cron:

20 0 * * * php -q /home/user/public_html/tssol/contract/admin/cron_removeOld.php

PHP (Line 35):

$stmt = $dbh->prepare("SELECT idusers, contract FROM users WHERE contractExpireDate <= NOW()");

The db creds are in an include file that is shared with other pages so I know thats not an issue..will post if you think it will help

1

There are 1 best solutions below

1
On

MySQL permission has nothing to do with PHP executed by CLI or whatever.
Check if your mysql user has the SELECT provileges for users table