Error trying to execute query Object of class mysqli_result could

0

Here is my code php that what it does is show in JSON the information of the table.

if($_SERVER["REQUEST_METHOD"]=="POST"){
include('conexion.php');

$result  = mysqli_query($con,"SELECT * FROM localidades").mysqli_error($con); //<<<<<<Aqui marca el fallo!
while ($row = $result->fetch_assoc()) {
     $arr[] = $row;
}
$json = json_encode($arr);
    echo $json;
}

ERROR

  

Object of class mysqli_result could not be converted to string

    
asked by DoubleM 02.01.2018 в 05:43
source

1 answer

1

The error is quite clear, PHP uses the . point to concatenate two or more values, in its code it tries to concatenate a mysqli_result which is what returns mysqli_query , with a string that is what returns mysqli_error which is incorrect.

It should perhaps be just a if , to validate this

if ($result = mysqli_query($con, "SELECT * FROM localidades")) {

    while ($row = mysqli_fetch_assoc($result)) {
         $arr[] = $row;
    }
    $json = json_encode($arr);
    echo $json;
}
    
answered by 02.01.2018 / 05:57
source