Home php Call to undefined function mysql_connect ()

Call to undefined function mysql_connect () [duplicate]

Author

Date

Category

Incident. Locally, this code worked. Uploaded to hosting error indicates line 4.

mysql_connect ("localhost", "root", "2") or die (mysql_error ());

Writes

Fatal error: Uncaught Error: Call to undefined function mysql_connect ()


Answer 1, authority 100%

This extension has been deprecated since PHP 5.5.0 and removed in PHP 7.0.0 . Use MySQLi or PDO_MySQL instead. Maybe the hosting has version 7 PHP .

Use mysqli_connect () :

$ link = mysqli_connect ("127.0.0.1", "my_user", "my_password", "my_db");
if (! $ link) {
  echo "Error: Unable to connect to MySQL." ... PHP_EOL;
  echo "Error code errno:". mysqli_connect_errno (). PHP_EOL;
  echo "Error text:". mysqli_connect_error (). PHP_EOL;
  exit;
}

Source

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions