[英]Cannot connect to MySQL Database with Cron job
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. 我正在尝试执行cron作业,以删除一年前停用其帐户的所有用户,该脚本在网站上有效,但是通过cron作业进行操作时,出现致命错误。
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: 这是我的users.cron.php文件:
<?php
$db = new PDO('mysql:host=dbhost.com:port; dbname=dbname;', 'user', 'pass');
$query = "DELETE FROM users WHERE account_deleted='4'";
$db->query($query);
?>
Most Apache/PHP installations have 2 seperate php.ini
files. 大多数Apache / PHP安装都有2个单独的
php.ini
文件。
I would say that the one used by Apache/PHP is fine, but the other one does not have the PDO extension activated. 我想说Apache / PHP使用的一个很好,但是另一个没有激活PDO扩展。
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. 从命令行开始,您将看到一行告诉您PHP CLI从何处获取其
php.ini
文件的行。 Edit that so that the 编辑它,以便
extension=php_pdo_mysql.so
is activated 被激活
The Fatal error: Cannot instantiate non-existent class error message was shown by good old PHP/4 . 致命错误: 旧的PHP / 4显示了无法实例化不存在的类错误消息。 The PDO class requires PHP/5.1.0 or greater.
PDO类要求PHP / 5.1.0或更高版本。 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 eg 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.) (这些是伪造的路径,不要只是复制它们期望工作的路径。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.