I’m trying to run a cronjob in cPanel which gives me the following error:
Fatal error: Uncaught Error: Class ‘mysqli’ not found in /home/example/public_html/new_facebook_csv/csv_generator1.php:180
If run that file through browser by using the link example.com/new_facebook_csv/csv_generator1.php i get the right resaults without any errors, but if i try to run it with a cron job i get the error "Class ‘mysqli’ not found".
The cron job I’m running is the following:
php /home/example/public_html/new_facebook_csv/csv_generator1.php > /home/example/public_html/new_facebook_csv/facebook.log
and here is the logs i get after the cron job:
X-Powered-By: PHP/7.3.22
Content-type: text/html; charset=UTF-8
<br />
<b>Fatal error</b>: Uncaught Error: Class 'mysqli' not found in /home/example/public_html/new_facebook_csv/csv_generator1.php:180
Stack trace:
#0 {main}
thrown in <b>/home/example/public_html/new_facebook_csv/csv_generator1.php</b> on line <b>180</b><br />
I added the mysqli extension in the php.ini (extension=php_mysql.dll) but not luck with that.
Also check if mysqli is installed to my server with this commaned:
php -m|grep mysql
and that was my output
mysqli
mysqlnd
pdo_mysql
which means that mysql is installed to my server
2
Answers
try with curl like
/usr/bin/curl example.com/new_facebook_csv/csv_generator1.php
or you can use wget
wget -q -O- example.com/new_facebook_csv/csv_generator1.php
This is how I scheduled a cron job in cPanel through GoDaddy that runs the script and includes MYSQLI:
I tried many variations including cPanel’s example on running a PHP script with a cron job. I tried php in front of the script path, and the same format you used above, as well as the suggested answers and I received the same errors. Just using curl -s and then the url of your php script will do the trick.