What are potential security risks associated with using mysql_* functions in PHP?

Using mysql_* functions in PHP poses security risks such as SQL injection attacks, as these functions do not provide adequate protection against malicious input. To mitigate this risk, it is recommended to use parameterized queries or prepared statements with PDO or mysqli functions, as they automatically escape input data.

// Example of using prepared statements with PDO to prevent SQL injection
$pdo = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password');
$stmt = $pdo->prepare('SELECT * FROM users WHERE username = :username');
$stmt->bindParam(':username', $username);
$stmt->execute();
$result = $stmt->fetch();