What are the potential pitfalls of using the mysql extension in PHP for database connectivity?
The mysql extension in PHP is deprecated and no longer maintained, making it vulnerable to security risks and compatibility issues with newer versions of PHP. To address this, it is recommended to switch to the mysqli or PDO extension for database connectivity in PHP.
// Using mysqli extension for database connectivity
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "dbname";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";