Why is it recommended to use mysqli or PDO instead of the deprecated mysql functions in PHP?

The deprecated mysql functions in PHP are no longer supported and pose security risks due to their vulnerability to SQL injection attacks. It is recommended to use mysqli or PDO instead, as they provide more secure and flexible ways to interact with databases, as well as support for prepared statements to prevent SQL injection.

// Using mysqli to connect to a database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

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

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