forked from hussien89aa/AndroidTutorialForBeginners
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhpMySqlQuery.php
More file actions
26 lines (26 loc) · 701 Bytes
/
PhpMySqlQuery.php
File metadata and controls
26 lines (26 loc) · 701 Bytes
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
<?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()); }
// define quesry
$query="select * from logins"; // $usename=$_GET['username'];
$result= mysqli_query($connect, $query);
if(! $result)
{ die("Error in query");}
//get data from database
//$output=array();
while($row= mysqli_fetch_assoc($result))
{
$output[]=$row; //$row['id']
}
print(json_encode($output));// this will print the output in json
// 4 clear
mysqli_free_result($result);
//5- close connection
mysqli_close($connect);
?>