Why are the mysql_* functions considered outdated and discouraged for use?

The mysql_* functions are considered outdated and discouraged for use because they are deprecated as of PHP 5.5 and removed in PHP 7. Instead, developers are encouraged to use MySQLi or PDO extensions for database interactions as they offer more features, better security, and support for prepared statements to prevent SQL injection attacks.

// Using MySQLi extension to connect to a MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

echo "Connected successfully";