What are the recommended alternatives to the deprecated mysql_* functions in PHP for database queries?

The recommended alternatives to the deprecated mysql_* functions in PHP for database queries are to use either MySQLi (MySQL Improved) or PDO (PHP Data Objects) extensions. These extensions provide improved security features and support for prepared statements, making them more secure and versatile options for interacting with databases in PHP.

// Using MySQLi extension
$mysqli = new mysqli('localhost', 'username', 'password', 'database_name');
if ($mysqli->connect_error) {
    die('Connection failed: ' . $mysqli->connect_error);
}

$result = $mysqli->query("SELECT * FROM table_name");
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        // Process the data
    }
}

$mysqli->close();
```

```php
// Using PDO extension
$pdo = new PDO('mysql:host=localhost;dbname=database_name', 'username', 'password');
$statement = $pdo->query("SELECT * FROM table_name");
while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
    // Process the data
}

$pdo = null;