What are the potential pitfalls of using mysql_connect in PHP?
Using `mysql_connect` in PHP is not recommended as it is deprecated as of PHP 5.5.0 and removed in PHP 7.0.0. It is advised to use `mysqli_connect` or `PDO` for connecting to MySQL databases to ensure compatibility with newer PHP versions and to benefit from improved security features.
// Using mysqli_connect instead of mysql_connect
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";