Home >Database >Mysql Tutorial >Why Do I Get 'Undefined Function mysql_connect()' Even After Installing php5-mysql?

Why Do I Get 'Undefined Function mysql_connect()' Even After Installing php5-mysql?

DDD
DDDOriginal
2024-12-04 19:09:11655browse

Why Do I Get

Resolving "Undefined Function mysql_connect()" Error

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn