What are the potential pitfalls of mixing mysqli and mysql API functions in PHP?

Mixing mysqli and mysql API functions in PHP can lead to errors and unexpected behavior due to differences in how the two APIs handle connections and queries. To avoid this, it's important to stick to one API (preferably mysqli) throughout your codebase. If you need to switch from mysql to mysqli, make sure to update all relevant functions and queries to use the mysqli API.

// Example of using only mysqli API functions
$mysqli = new mysqli("localhost", "username", "password", "database");

if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
}

$result = $mysqli->query("SELECT * FROM table");

if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        echo "ID: " . $row["id"] . " - Name: " . $row["name"] . "<br>";
    }
} else {
    echo "0 results";
}

$mysqli->close();