0

I am connected to a database and when I try and get the data stored in it using mysqli_query it doesn't work. When I echo the $result nothing shows up. When I use var_dump($result) I get `bool(false). By the way, the connection is working. Why isn't it working?

I have tried to change the names of the variables, I have read a lot of Q&A from other people and I can't figure out why is it not working.

<?php 
    require('database/dbconnection.php');

    $query = 'SELECT * FROM users';

    $result = mysqli_query($conn, $query);
    var_dump($result);

    $usersDate = mysqli_fetch_all($result, MYSQLI_ASSOC);
    var_dump($usersDate);

    mysqli_free_result($result);

    mysqli_close($conn);
?>

I expected to get the data and var_dump() it. But I cant because the query doesn't work.

$conn is the var I got when I required the dbconnection.php file

nerdlyist
  • 2,842
  • 2
  • 20
  • 32
GevaS
  • 1
  • 3
  • 1
    and if you do a var_dump of the $conn param after your require, what do you get then? – Ole Haugset Jan 28 '19 at 18:52
  • False is usually from something failing. Are you sure your connection is made? How are you sure. Is the users table created? – nerdlyist Jan 28 '19 at 18:52
  • Try checking for [mysqli errors](http://php.net/manual/en/mysqli.error.php) after your query to see what it's returning. – aynber Jan 28 '19 at 18:53
  • Also, `echo` and `var_dump` treat false vastly different that is why on is blank echo converts false to a string false or blank where var_dumb cares about type. You are not getting null just false outputted differently. – nerdlyist Jan 28 '19 at 18:55

0 Answers0