What are some potential security risks associated with using the outdated mysql extension in PHP?
Using the outdated mysql extension in PHP can pose security risks such as SQL injection attacks and lack of support for modern security features. To mitigate these risks, it is recommended to switch to the mysqli or PDO extension, which provide better security features and support for prepared statements.
// Connect to MySQL using mysqli extension
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}