What potential issues can arise when using the mysql_query function in PHP, and what are the recommended alternatives?

Using the mysql_query function in PHP can lead to SQL injection vulnerabilities and is deprecated as of PHP 5.5.0. It is recommended to use either PDO (PHP Data Objects) or MySQLi (MySQL Improved) extensions to interact with MySQL databases securely.

// Using PDO to query the database securely
$pdo = new PDO('mysql:host=localhost;dbname=database_name', 'username', 'password');
$stmt = $pdo->prepare('SELECT * FROM table_name WHERE column = :value');
$stmt->bindParam(':value', $value);
$stmt->execute();
$results = $stmt->fetchAll();