What are the potential pitfalls of using outdated MySQL functions like mysql_connect in PHP?
Using outdated MySQL functions like mysql_connect in PHP can lead to security vulnerabilities and compatibility issues with newer versions of MySQL. It is recommended to switch to MySQLi or PDO for improved security and compatibility with modern PHP practices.
// Connect to MySQL using MySQLi
$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";