What are the potential pitfalls of using mysql_query to fetch IDs in PHP?

Using mysql_query to fetch IDs in PHP can be risky as it is deprecated and not recommended for use due to security vulnerabilities such as SQL injection. To solve this issue, it is recommended to use PDO or MySQLi extension with prepared statements to safely fetch IDs from the database.

// Fix using PDO with prepared statements to fetch IDs safely
$pdo = new PDO('mysql:host=localhost;dbname=my_database', 'username', 'password');
$stmt = $pdo->prepare("SELECT id FROM my_table WHERE condition = :condition");
$stmt->bindParam(':condition', $condition_value);
$stmt->execute();
$ids = $stmt->fetchAll(PDO::FETCH_COLUMN);