Why is it recommended to avoid using the mysql_* functions in PHP, and what are the alternatives?

It is recommended to avoid using the mysql_* functions in PHP because they are deprecated and have been removed in newer versions of PHP. Instead, it is recommended to use MySQLi (MySQL Improved) or PDO (PHP Data Objects) for database operations. These alternatives provide more secure and efficient ways to interact with databases.

// Using MySQLi
$mysqli = new mysqli("localhost", "username", "password", "database");

if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
}

// Using PDO
$pdo = new PDO("mysql:host=localhost;dbname=database", "username", "password");