What are the potential security risks associated with using the mysql_* extension in PHP, and what are the recommended alternatives?

The mysql_* extension in PHP is deprecated and poses security risks due to its vulnerability to SQL injection attacks. It is recommended to use either MySQLi (MySQL Improved) or PDO (PHP Data Objects) extensions, which provide more secure and flexible ways to interact with databases.

// Using MySQLi extension
$mysqli = new mysqli('localhost', 'username', 'password', 'database_name');
if ($mysqli->connect_error) {
    die('Connection failed: ' . $mysqli->connect_error);
}

// Using PDO extension
$pdo = new PDO('mysql:host=localhost;dbname=database_name', 'username', 'password');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);