MySQL temporary tables

2

I'm here to study the MySQL temporary tables, and I'm creating some temporary tables. I'm using mysqli , according to the manual , temporary tables delete after the connection is closed.

But the truth is that this does not happen to me, temporary tables are deleted even when I do not close the connection . Is it really the behavior, or is it I'm getting the water?

PHP Code:

$mysqli     = new mysqli(HOST, USER_NAME, PASSWORD, DATA_BASE);
mysqli_set_charset($mysqli, CHARSET);

$sql_create = "CREATE TEMPORARY TABLE ...";     
$mysqli->query($sql_create));

//$mysqli->close();
    
asked by anonymous 15.05.2014 / 17:04

1 answer

2

What happens is that PHP closes the connection anyway at the end of script , so if we want to check if we are doing everything right we can for example do a select on this same table just below the creation of it, in the same PHP file (and before close , as we have to take advantage of the connection that is already open).

Example:

   if ($result = $mysqli->query("select * from TABELA"))
   {
      while($obj = $result->fetch_object())
      {
         echo "Campo1: ".$obj->campo1."; ";
         echo "Campo2: ".$obj->campo2;"; ";
         ...
         echo "<br>";
      }
   }
   $result->close();

Source: Bacco

    
15.05.2014 / 17:37