-3

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/u195296372/public_html/include/header.php on line 21

I had this error in my header.

This is the code (line 21 and 22):

mysql_connect("$host", "$username", "$password")or die("cannot connect to the database."); 
mysql_select_db("$db_name")or die("cannot select the database.");
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119

1 Answers1

0

Use mysqli instead.

Your code would look like this:

mysqli_connect("$host", "$username", "$password")or die("cannot connect to the database.");
mysqli_select_db("$db_name")or die("cannot select the database.");

Or, in object-oriented style:

$mysqli = new mysqli("$host", "$username", "$password", "$db_name");
if ($mysqli->connect_errno) {
    die("database connection failed.");
}

Then you can do queries like this:

$result = $mysqli->query("[SQL query]");

MySqli documentation

Aloso
  • 5,123
  • 4
  • 24
  • 41