-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.php
34 lines (30 loc) · 1.03 KB
/
main.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
<?php
header('Access-Control-Allow-Origin: *');
// error_reporting(0);
$servername = "localhost";
$username = "******";
$password = "**********";
$dbname = "**********";
// Create connection
$new = new mysqli($servername, $username, $password,$dbname);
// Check connection
if ($new->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM input";
$result = $new->query($sql);
$str = "{";
$length = $result->num_rows;
$count=0;
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$str.='"'.$row["id"].'":'.'{"name":"'.$row["name"].'","phone":"'.$row["phone"].'","dept":"'.$row["department"].'","hosp":"'.$row["hospital"].'","place":"'.$row["place"].'"}';
$count++;
if($count!=$length){
$str.=",";
}
}
}
$str.="}";
echo $str;
?>