What potential issues can arise from using deprecated functions like mysql_connect in PHP?
Using deprecated functions like mysql_connect in PHP can lead to security vulnerabilities and compatibility issues with newer versions of PHP. It is recommended to switch to using mysqli or PDO for database connections, as they offer better security features and support for prepared statements to prevent SQL injection attacks.
// 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";