How can the code be optimized to improve performance, considering the use of deprecated mysql extension and SELECT * queries?

Using deprecated mysql extension and SELECT * queries can impact performance due to outdated technology and retrieving unnecessary data. To optimize the code, switch to mysqli or PDO extension for database operations and avoid using SELECT * by specifying only the needed columns in the query.

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

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

// Query with specific columns
$result = $mysqli->query("SELECT column1, column2 FROM table_name");

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

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