-2

I'm getting this error from a PHP file:

The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead

Here's a copy of the relevant code:

<?php
$con = mysql_connect("localhost","username","password");
if (!$con) {
  die('Could not connect: ' . mysql_error());
}

mysql_select_db("database_name", $con);

$result = mysql_query("SELECT COUNT(*) FROM `tbltodolist` WHERE status = 'Pending'");
$row = mysql_fetch_array($result);
$total = $row[0];

echo $total;

mysql_close($con);
?>

Is there any simple way to switch this to using mysqli to avoid the error?

Edward
  • 343
  • 6
  • 12
  • 9
    This question is probably older than the earth itself: http://stackoverflow.com/questions/13944956/the-mysql-extension-is-deprecated-and-will-be-removed-in-the-future-use-mysqli – Christian Jul 24 '16 at 07:47

2 Answers2

1

Use mysqli in this way to avoid notice. Because mysql is deprecated with new versions of php.

<?php
$con = mysqli_connect("localhost","username","password","database_name");
if (!$con) {
  die('Could not connect: ' . mysqli_error());
}
$result = mysqli_query($con,"SELECT COUNT(*) FROM `tbltodolist` WHERE status = 'Pending'");
$row = mysqli_fetch_array($result);
$total = $row[0];

echo $total;

mysqli_close($con);
?>
Devsi Odedra
  • 5,244
  • 1
  • 23
  • 37
0

Use mysqli instead mysql. For More Information Follow this Link or this Link

Community
  • 1
  • 1
Muzafar Khan
  • 826
  • 3
  • 15
  • 28