我无法使用sql查询数据填充数组,以将其导出为php中的json对象

I am new with php, I try to call the following function in order to populate an array of previously inserted data in mysql, but I get null.

function GetBusiness($con, $email) 
 {    
    $query = "SELECT * from Business WHERE B_EMAIL ='".$email."'";    
    $res = mysqli_query($con,$query); 
    $result_arr = array();
        while($row = mysqli_fetch_array($res))
        {
             $result_arr[] = $row;
        }
    return $result_arr;
}

and then I try to construct my json object as..

$result_business = array();
$result_business = GetBusiness($con, $email);
$json['result'] = "Success";
$json['message'] = "Successfully registered the Business";          
$json["uid"] = $result_business["id"];
$json["business"]["name"] = $result_business["name"];
$json["business"]["email"] = $result_business["email"];

but for even if the data are inserted successfully the part of $result_business is null, why I get null? I my $query typed wrong?

thank you

The problem is, your function GetBusiness returns a multi-dimensionnal array, you can use this one instead :

function GetBusiness($con, $email)
{
    $query = "SELECT * from Business WHERE B_EMAIL ='".$email."'";
    $res = mysqli_query($con,$query);
    return mysqli_fetch_array($res);
}

Also, you must use the MySQL columns that you selected to access the data of the rowset. Something like

$json["uid"] = $result_business["B_ID"];
$json["business"]["name"] = $result_business["B_NAME"];