Reputation: 657
I'm trying to make a cron job to delete any users that have deactivated their accounts a year ago, the script works on the website but when doing it through a cron job, I get a fatal error.
Fatal error: Cannot instantiate non-existent class: pdo in /homepages/9/d526231279/htdocs/cupidmemories/cronjobs/users.cron.php on line 2
Here is my users.cron.php file:
<?php
$db = new PDO('mysql:host=dbhost.com:port; dbname=dbname;', 'user', 'pass');
$query = "DELETE FROM users WHERE account_deleted='4'";
$db->query($query);
?>
Upvotes: 0
Views: 1270
Reputation: 146460
The Fatal error: Cannot instantiate non-existent class error message was shown by good old PHP/4. The PDO class requires PHP/5.1.0 or greater. You simply cannot use such an outdated interpreter to run anything that resembles modern code.
Hopefully, your hosting provider might have a newer interpreter available if you provide the appropriate full path, so you could replace this:
*/10 * * * * php /homepages/9/d526231279/htdocs/cupidmemories/cronjobs/users.cron.php
... with e.g. this:
*/10 * * * * /opt/php5.6/bin/php /homepages/9/d526231279/htdocs/cupidmemories/cronjobs/users.cron.php
(These are fake paths, don't just copy them expecting to work.)
Upvotes: 1
Reputation: 94662
Most Apache/PHP installations have 2 seperate php.ini
files.
I would say that the one used by Apache/PHP is fine, but the other one does not have the PDO extension activated.
Do a
>php --ini
from the command line and you will see line which tells you where PHP CLI got its php.ini
file from. Edit that so that the
extension=php_pdo_mysql.so
is activated
Upvotes: 1