Home  >  Article  >  Backend Development  >  How do I Fix the \"Undefined Function mysql_connect()\" Error in PHP?

How do I Fix the \"Undefined Function mysql_connect()\" Error in PHP?

Linda Hamilton
Linda HamiltonOriginal
2024-10-31 02:52:31877browse

How do I Fix the

Troubleshooting "Undefined Function mysql_connect() Error" in PHP

When attempting to utilize the mysql_connect() function, users may encounter the error "undefined function mysql_connect()." This error often occurs despite installing the php5-mysql package and restarting the necessary services.

Resolution:

To resolve this issue, consider the following approaches:

For PHP7:

  • Mysql_ functions have been removed entirely in PHP7. It is recommended to update your code to use PDO-functions or mysqli_ functions instead.

Workaround for PHP5:

  • Create a small PHP include file that recreates the mysql_ functions using mysqli_() functions, such as fix_mysql.inc.php. This allows you to continue using the old mysql_* functions.

The above is the detailed content of How do I Fix the \"Undefined Function mysql_connect()\" Error in PHP?. 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