-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbread.php
More file actions
55 lines (47 loc) · 1.07 KB
/
dbread.php
File metadata and controls
55 lines (47 loc) · 1.07 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
// 1- connect to db
$host="127.0.0.1";
$user="root";
$password="12345";
$database="admins";
$connect= mysqli_connect($host, $user, $password, $database);
if(mysqli_connect_errno()){
die("cannot connect to database field:". mysqli_connect_error());
}
else {
echo 'Database is connected';
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
//2- read from database
$query="select * from logins";
$result= mysqli_query($connect, $query);
if(! $result){
die("Error in query");
}
?>
<ul>
<?php
// 3- write or display data
while($row= mysqli_fetch_assoc($result)){
echo '<li>id:'.$row['id'] .', username:' .$row['username'].', password:' .$row['password'] ."</li>";
}
?>
</ul>
<?php
// 4 clear
mysqli_free_result($result);
?>
</body>
</html>
<?php
//5 close connection
mysqli_close($connect);
?>