Why is it recommended to avoid using mysql_* functions in PHP and switch to PDO or mysqli?

Using mysql_* functions in PHP is not recommended because they are deprecated as of PHP 5.5 and removed in PHP 7. Additionally, these functions are prone to SQL injection attacks and do not support prepared statements, making them less secure. It is recommended to switch to either PDO or mysqli, which offer more secure ways to interact with a database and support prepared statements to prevent SQL injection attacks.

// Using mysqli 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";