<?php
$databasehost = "127.0.0.1";
$databasename = "search";
$databaseusername ="root";
$databasepassword = "";

//////////////////////////////////////////////////////////////
 
$name=$_GET['user_name'];
$con = mysqli_connect($databasehost,$databaseusername,$databasepassword) or die(mysqli_error($con));
mysqli_select_db($con,$databasename) or die(mysqli_error($con));
mysqli_query($con,"SET CHARACTER SET utf8");

$query="SELECT * FROM `users` WHERE username like '%".$name."%'";

$sth = mysqli_query($con,$query);
if (mysqli_errno($con)) {
    header("HTTP/1.1 500 Internal Server Error");
    echo $query.'\n';
    echo mysqli_error($con);
}else{
    $rows = array();
    while($r = mysqli_fetch_assoc($sth)) {
        $rows[] = $r;
    }
     mysqli_close($con);
     print json_encode(array("result"=>$rows));
}
?>