I have tried the following:
<?php
require("config/conf.php"); //El fichero donde se conecta a la base de datos
$consulta = "SELECT * FROM `users`";
$resultado = mysqli_query($conexion, $consulta);
$rawdata = array();
$i = 0;
while($row = mysqli_fetch_array($result)) {
$rawdata[$i] = $row;
$i++;
}
echo json_encode($rawdata);
?>
Please someone help me the deploy is very soon and I need it urgently.
I propose this code, with error control, and avoiding unnecessary things, such as a counter
$i
inside the loop.Consider that the DBMS have their own table
users
, the code may fail because of that, whatever it is, you will see it with a robust code. Here we go:As you can see, we have written a robust program, which will always return a result, with an error, indicating what has failed, be it with the data. It is a longer code, it will shout some! Well, yes, but that's how it should be, one of the main tasks of a programmer is to think about everything that could go wrong (pessimistic programming), not to complain, but to adequately deal with those problems. It is a very neglected aspect in programming, which leads to writing weak programs. Things don't always work the way you want them to.