PHP cron job error Call to undefined function mysql_connect()

Avatar
  • Answered
I've had a php cron job set up to update a database value. It worked correctly, running daily at 1 PM until it began giving the following error, starting on June 2 (and every day since):
X-Powered-By: PHP/7.0.18
Content-type: text/html; charset=utf-8
Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /(my script path)/cron/cleanup.php:2

I need the php script to be able to connect to my database to function correctly. What is needed to correct this behavior?
Avatar
IMH Support Agent 5
Hello, Thank you for your question about PHP errors. It is most likely this error occurs because the mysql_connect() function was deprecated as of PHP version 5.5.0 and removed entirely from version 7. It is possible that your PHP installation was upgraded to version 7, and this is may be the reason why the error suddenly started. You can revert to an older version of PHP, but it would be wiser to do as the PHP manual advises and update the code throughout your site to use MySQLi instead of mysql_connect(). Best, Christopher M.