In the context of PHP development, what are the implications of the deprecation of the mysql_* functions in PHP 5.5 and the transition to mysqli or PDO?
The deprecation of the mysql_* functions in PHP 5.5 means that these functions are no longer supported and may lead to security vulnerabilities and compatibility issues. To address this, developers should transition to using either the mysqli extension or PDO for database operations in PHP.
// Using mysqli to connect to a MySQL 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);
}
// Perform SQL query
$sql = "SELECT * FROM table";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// Output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["name"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();