What are the recommended alternatives to using mysql_* functions in PHP for database operations?

The recommended alternatives to using mysql_* functions in PHP for database operations are to use either MySQLi (MySQL Improved) or PDO (PHP Data Objects) extensions. These extensions provide improved security features, support for prepared statements, and better overall performance compared to the deprecated mysql_* functions.

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

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

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

// Fetch data
while ($row = $result->fetch_assoc()) {
    echo $row['column_name'] . "<br>";
}

$mysqli->close();