Home > Database > Mysql Tutorial > body text

Why is `mysql_connect()` Deprecated in PHP 7 and How Do I Fix It?

Mary-Kate Olsen
Release: 2024-11-22 03:27:11
Original
629 people have browsed it

Why is `mysql_connect()` Deprecated in PHP 7 and How Do I Fix It?

Undefined Function 'mysql_connect()' in PHP

You've configured PHP, MySQL, and Apache, and localhost() functions correctly in PHP. However, after installing MySQL, you encounter the error:

Fatal error: Call to undefined function mysql_connect()
Copy after login

This issue arises because you have upgraded to PHP 7, where the mysql_connect function is deprecated. To resolve it:

  1. Check your PHP version with php -version.
  2. Replace mysql_connect with mysqli_connect in your code:
$host = "127.0.0.1";
$username = "root";
$pass = "foobar";
$con = mysqli_connect($host, $username, $pass, "your_database");
Copy after login

If you're migrating legacy PHP code, you'll need to convert all your mysql_* functions to mysqli_* equivalents.

The above is the detailed content of Why is `mysql_connect()` Deprecated in PHP 7 and How Do I Fix It?. 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