How can the use of deprecated functions like mysql_query be replaced with modern alternatives like mysqli or PDO for better security and performance?

The use of deprecated functions like mysql_query should be replaced with modern alternatives like mysqli or PDO for better security and performance. This is because mysqli and PDO offer prepared statements and parameterized queries, which help prevent SQL injection attacks. To replace mysql_query with mysqli or PDO, you need to update the connection code and query execution code in your PHP application.

// Using mysqli
$mysqli = new mysqli($host, $user, $password, $database);

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

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

$mysqli->close();
```

```php
// Using PDO
$pdo = new PDO("mysql:host=$host;dbname=$database", $user, $password);

$stmt = $pdo->query("SELECT * FROM table");

while ($row = $stmt->fetch()) {
    // Process the data
}

$pdo = null;