Jump to content

mysqli free results


pepelepew1962

Recommended Posts

require("dbcon.php");

// Check for errors
if(mysqli_connect_errno())
{
   echo mysqli_connect_error();
}

// Create a prepared statement
if($stmt = $mysqli -> prepare ("SELECT id, username, password FROM users WHERE password=?"))
{
// Bind parameters s - String, b - Boolean, i - Integer etc
$password='123';

$stmt -> bind_param("s", $password);

// Execute it
$stmt -> execute();

// Bind result variables
$stmt->bind_result($id,$username,$password);

// Fetch the result of the query
while($stmt->fetch())
{
   echo $id . ' - ' . $password . ' - ' . $username;
   echo "<br />";
}

// Close statement
 $stmt -> close();
}
// Close connection
$mysqli -> close();

Hello:

 

I am trying to convert to mysqli and on the net I constant see examples of freeing the memory after running the query.  All the examples I have seen are based on 1 result from the query.  Well I have multiple fields in my bind results and can not get something to the effect of:

 

mysqli_free_result ($result)

 

Can anyone help me here please.  How can I free the results in my code?

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

Seems to me that mysqli_free_result frees all of the result memory, so there's no specifying individually bound results. IOW binding results to vars just creates individual references to the core result source.

 

Sidenote: perhaps it might be helpful if you provided more background to what you're trying to do. As it stands in your code, there's no real gain from doing this.. or from closing the statement/connection at the end of your script like that. php automatically closes and frees everything at the end of script execution. The only time it's really beneficial to do this sort of thing is if you're working with a database and getting results.. but then the script still has a lot of stuff to do afterwards and you don't want the db stuff sitting in memory causing the rest of the script to run slower.

Link to comment
Share on other sites

$result = NULL; 

 

would free something up.

 

I feel as if freedom to submit arbitrary data that was-or-wasnot asked for is a possible danger to the integrity of a php site.

 

The mysql "connection" should be just a DB password in the php's mind without overhead -- barring negligent SQL commands to your server.  If you really want it free, shutting down the server is defunct.



while($stmt->fetch())
{
echo $id . ' - ' . $password . ' - ' . $username;
echo "<br />"
}

The fetch process would have contained in the php's backend. It is calmer approach.  Is a liability because the MySql DB server does not intend to server a single client especially if he is rate limiting.

 

Cynical, but these are theorys that have been suggested to me. The backends left me with little to cling to data wise when they were asked to do anything at all.

 

The attraction is that it is a convenient storage and organizational friend that may slow things down closer to the rate at which they are used.  

 

Password oriented retrieval is an interesting venture there, btw.  >

Edited by Augury
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.