I am new to php and mysqli and have been going through and trying to understand how a lot of these built in functions work. I have read the documentation and many tutorials/examples.
I have something like:
$conn = new mysqli(vars); <br />
$sql = "Select * from Users where name ='$name'";
$result = $conn->query($sql);
$pass = result->fetch_assoc()['Pass'];
//check password stuff
that works fine, however if I then try to use $result->fetch_assoc()['ID']
it returns null. If I swap the order of ID and Pass then the id returns and pass comes back null.
I don't understand why this is the case. What I think (which is clearly wrong) is that result should store the whole row (which it does) and then when i fetch assoc I should just be pulling data from the row. However it seems to be overwriting result when I fetch assoc. What's up with that?
My work around is to call the query multiple times for each data point i need to start a session and store variables, and I know I can use prepared statements, but I feel like there's a better way and I'm missing it.
Can someone please explain?