简体   繁体   中英

MySQL Permissions for CRON job

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:

: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[42000]: Syntax error or access violation: 1142 SELECT command denied to user 'username'@'localhost' for table 'users' in on line :PDOStatement::execute() [pdostatement.execute]: SQLSTATE[42000]: 语法错误或访问冲突:1142 SELECT 命令拒绝用户 'username'@'localhost' 用于行中的表 'users'

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

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

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