-
Notifications
You must be signed in to change notification settings - Fork 0
/
2_1.php
36 lines (32 loc) · 760 Bytes
/
2_1.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
$conn = OpenCon();
$sql = "SELECT first_name, last_name FROM employees ORDER BY last_name";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo $row["first_name"]. " " . $row["last_name"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
function OpenCon()
{
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$db = "employees";
$conn = new mysqli($dbhost, $dbuser, $dbpass,$db) or die("Connect failed: %s\n". $conn -> error);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}else{
echo("oppkobling vellykket"."<br>");
}
return $conn;
}
function CloseCon($conn)
{
$conn -> close();
}
?>