mysqli_query() within mysqli_fetch_assoc() dispenses with the use of mysqli_free_result?

Asked

Viewed 208 times

1

With the new Mysql class, mysqli, it has become necessary to worry about always making use of mysqli_free_result() after mysqli_query() with SELECT for memory release, but I often use mysqli_query() inside mysqli_fetch_assoc() and in this case I don’t have a variable with the result of mysqli_query().

What I would like to know is if this procedure of mine can lead to misuse of memory, that is, if I really have to make a code to use mysqli_free_result() or not? See example:

WITH the use of mysqli_free_result():

$query = "SELECT * FROM .... LIMIT 1";
$result = mysqli_query($conn, $query);
$registro = mysqli_fetch_assoc($result);
mysqli_free_result($result);
mysqli_close($conn);

WITHOUT the use of mysqli_free_result():

$query = "SELECT * FROM .... LIMIT 1";
$registro = mysqli_fetch_assoc(mysqli_query($conn, $query));
mysqli_close($conn);
</pre>
  • 1

    I’d say you shouldn’t use the function directly on mysqli_fetch_assoc...

  • 1

    putting a function inside the other function would be an error, the good thing is that each line perform separately given function, debug and maintenance thank in this style...!!! the mysqli_free_result also existed in the old mysql http://php.net/manual/en/function.mysql-free-result.php

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.