What potential issue could arise when using the mysql extension in PHP for database queries, and what alternative extensions are recommended for modern PHP development?
The potential issue that could arise when using the mysql extension in PHP for database queries is that it is deprecated as of PHP 5.5.0 and removed in PHP 7.0.0. It is recommended to use either the mysqli extension or PDO (PHP Data Objects) for modern PHP development.
// Using mysqli extension to connect to a MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";