"Call to undefined function mysql_connect()" error on PHP 7

Post Reply
User avatar
Vanderburg
Former staff
Former staff
Posts: 1253
https://www.youtube.com/channel/UC40BgXanDqOYoVCYFDSTfHA
Joined: Sat Nov 13, 2010 7:27 am
Location: Dallas, TX

"Call to undefined function mysql_connect()" error on PHP 7

Post by Vanderburg »

If you're receiving the following error:

Code: Select all

Uncaught Error: Call to undefined function mysql_connect() in /usr/www/identifier/public/forums/functions/db.php:324
...this is due to the deprecated mysql extension no longer being included, breaking all "mysql_" functions. Ideally, you should update or convert your software to use mysqli or PDO, but if those aren't options in the short term, you might try applying a shim that recreates the functions.
  1. Download the shim here: https://raw.githubusercontent.com/dshaf ... /mysql.php
  2. Upload the mysql.php file to your webhosting. Place it in the includes folder for your website, or a directory where typical config files can be found, if available
  3. Locate a common file that is that is included everywhere in your software. Often this file is called "config.php" or "Settings.php" or similar. Edit that file to add this before other PHP statements:

    Code: Select all

    include_once('./mysql.php');
    1. This assumes the shim is in the same directory as the config file. If it's one directory up, you'll use '../mysql.php' and if it's one directory down, you'll use './folder_name/mysql.php'.
    2. If you do not have a common config file, the line above will need to be included in all files using MySQL.
Post Reply