The Line $query=$db->query("SELECT * FROM accidente")
basically what you are doing is to execute the query passed by parameter and the return value will be a mysqli_result
(if executed correctly) then assign it to your variable $query
(in case there is an error it will return false)
In line $result = mysqli_query($query, $db)
you execute the query in theory again, but there is an error and that is that the order of the parameters are mysqli_query($db,$query)
but not your variable because if it was executed successfully the first will have a mysqli_result
, in case of errors a value FALSE
and not a query itself.
To solve this, you must first choose an option to perform query
if you choose the first one, your code would be
$query=$db->query("SELECT * FROM accidente");
while ($rows = $query->fetch_array(MYSQLI_ASSOC)){
print_r($rows);
}
If you choose the second way it would be.
$result = mysqli_query($db,"select * from accidente");
while ($rows = mysqli_fetch_array($result)){
print_r($rows);
}
As an additional note, I suggest using sentences prepared with
extension PDO
and it would not hurt to read How to avoid
SQL injection?