<?php
$host= “localhost”;
$user= “username”;
$pass= “password”;
$dbname = “employee”;
// Create connection
$conn = new mysqli($host, $user, $pass, $dbname);
if ($conn->connect_error) {
die(“Connection failed: ” . $conn->connect_error);
}
$result = $conn->query(“SELECT * FROM employee order by salary desc limit 5”);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo “id: ” . $row[”id”]. ” – Name: ” . $row[”first_name”]. ” ” . $row[”last_name”]. “<br>”;
}
} else {
echo “0 results”;
}
$conn->close();
?>
the SQL is get five records whose salary are highest
Question and answer is powered by AnsPress.io