I have a couple of mysqli questions.
First. I know I can make groups into an array. I was just wondering if there was a way to get a row from the groups object without maki开发者_JAVA百科ng it into an array?
$groups = $this->db->query("SELECT id, name FROM groups");
...
<select name="group">
<?php while($group = $groups->fetch_object()): ?>
<option value="<?php echo $group->id?>"><?php echo $group->name; ?></option>
<?php endwhile; ?>
</select>
...
<?php echo $groups[$user->group_id]; ?>
I know the final line won't work. Is there something like this $groups->fetch_row($group_id)->name
?
My second question is to do with garbage collection. How much of a difference in a small application does it make if I free up a result as opposed to not? Instead of freeing up the result after each query could I close the database connection when the database class destructs. Would this have the same effect?
Use fetch_assoc()
:
<?php while($group = $groups->fetch_assoc()): ?>
<option value="<?php echo $group['id']; ?>"><?php echo $group['name']; ?></option>
<?php endwhile; ?>
精彩评论