What alternative to the MySQL extension was recommended for database operations in PHP?
The MySQL extension was deprecated in PHP 5.5.0 and removed in PHP 7.0.0, so it is recommended to use either the MySQLi (MySQL Improved) extension or PDO (PHP Data Objects) for database operations in PHP.
// Using MySQLi extension
$mysqli = new mysqli("localhost", "username", "password", "database_name");
if ($mysqli->connect_error) {
die("Connection failed: " . $mysqli->connect_error);
}
// Using PDO
$pdo = new PDO("mysql:host=localhost;dbname=database_name", "username", "password");
if (!$pdo) {
die("Connection failed: " . $pdo->errorInfo());
}