Home > Backend Development > PHP Tutorial > 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
Release: 2024-10-31 02:52:31
Original
918 people have browsed it

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template