What are the potential pitfalls of using both mysql_ and mysqli_ APIs in PHP code?

Mixing the mysql_ and mysqli_ APIs in PHP code can lead to compatibility issues and errors due to differences in function naming and parameter order. To avoid potential pitfalls, it's recommended to stick to one API (preferably mysqli_) for consistency and better security features.

// Example of using mysqli_ API instead of mixing with mysql_

// Connect to MySQL database using mysqli_
$mysqli = new mysqli('localhost', 'username', 'password', 'database');

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

// Perform a query using mysqli_
$result = $mysqli->query("SELECT * FROM table");

// Fetch data using mysqli_
while ($row = $result->fetch_assoc()) {
    // Process data
}

// Close connection
$mysqli->close();