What are the potential risks of mixing mysql_* with PDO in PHP code?

Mixing mysql_* functions with PDO in PHP code can lead to inconsistencies and potential security vulnerabilities. It is recommended to stick to one database extension for consistency and to avoid unexpected behavior. To solve this issue, refactor the code to use either mysql_* functions or PDO exclusively.

// Example of refactored code using only PDO

// PDO connection
$dsn = 'mysql:host=localhost;dbname=mydatabase';
$username = 'username';
$password = 'password';

try {
    $pdo = new PDO($dsn, $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    die("Error: " . $e->getMessage());
}

// Query using PDO
$stmt = $pdo->prepare("SELECT * FROM table_name");
$stmt->execute();
$results = $stmt->fetchAll();

foreach ($results as $row) {
    // Process results
}