What are the potential pitfalls of using the mysql extension in PHP for database queries?

Using the mysql extension in PHP for database queries is not recommended as it has been deprecated since PHP 5.5.0 and removed in PHP 7. Instead, it is recommended to use MySQLi or PDO extensions for better security and performance. To solve this issue, you should update your code to use MySQLi or PDO for interacting with databases.

// Using MySQLi extension for database queries
$mysqli = new mysqli("localhost", "username", "password", "database");

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

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

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        // Process each row
    }
} else {
    echo "0 results";
}

$mysqli->close();