What are the differences between using MySQL and other database management systems like DB2-QMF when writing PHP code for querying data?
When writing PHP code for querying data, the main differences between using MySQL and other database management systems like DB2-QMF lie in the syntax and functions used to connect to the database, execute queries, and retrieve results. It is important to familiarize yourself with the specific syntax and functions required by the database management system you are using in order to successfully query data.
// Example PHP code snippet for querying data using MySQL
// Connect to MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Execute SQL query
$sql = "SELECT * FROM table";
$result = $conn->query($sql);
// Fetch and display results
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "Name: " . $row["name"]. " - Email: " . $row["email"]. "<br>";
}
} else {
echo "0 results";
}
// Close connection
$conn->close();