开发者

2 MySQLi Questions

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; ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜