What are the potential security risks of using outdated MySQL functions in PHP code?
Using outdated MySQL functions in PHP code can pose security risks such as SQL injection attacks, data corruption, and vulnerability to hacking attempts. To mitigate these risks, it is recommended to use modern MySQL functions or switch to prepared statements to prevent SQL injection attacks.
// Using modern MySQL functions to connect to the 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);
}