Home >Database >Mysql Tutorial >Why Do I Get 'Undefined Function mysql_connect()' Even After Installing php5-mysql?
Despite installing php5-mysql, you continue to encounter the "Undefined function mysql_connect()" error. Let's delve into the issue and investigate possible solutions.
As the phpinfo() output indicates, the pdo_mysql.ini file has been parsed, suggesting the extension is loaded. However, the error implies that the mysql_* functions are not available.
If you are using PHP7, it's important to note that the mysql_ functions have been removed completely. Instead, you should consider using the PDO (PHP Data Objects) or mysqli_ functions. Updating your code to utilize these functions will resolve the issue.
Alternatively, if updating your code is not feasible, a workaround is available. You can create a PHP include file, fix_mysql.inc.php, which recreates the old mysql_ functions using mysqli_()-functions. This can act as a temporary fix until you can migrate your code to the newer functions.
The above is the detailed content of Why Do I Get 'Undefined Function mysql_connect()' Even After Installing php5-mysql?. For more information, please follow other related articles on the PHP Chinese website!