Mysql time tables

Asked

Viewed 1,455 times

2

I am here studying the temporary tables of Mysql, and I am creating some temporary tables. I am using the mysqli, according to the manual, the temporary tables are erased after the connection is closed.

But the truth is that it doesn’t happen to me, the temporary tables are erased even when I don’t do the close-up connection. It’s either behavior or I’m the one who’s screwing up?

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();
  • 2

    I think you need a little more detail in the example. How are you planning to use the table? Is it all in the same script? remembering that PHP will close the connection anyway at the end of the script.

  • I saw this article the other day help ? http://imasters.com.br/banco-de-dados/mysql/mysql-e-tabelas-temporarias/

  • @Bacco So there is no way for me to check if the tables were created? It was more for debug, just to make sure that the tables were created and if the content I insert is inserted.

  • @Motta I’ll see, it looks interesting.

  • @Jorgeb. gives, but you have to check in the same script. For example, making a select in this same table just below the creation of it, in the same PHP file (and before the close, because you have to take advantage of the connection that is already open).

  • @Bacco seems to me to be just that. I don’t know if the question is even pertinent to keep open, but if you want to do the answer.

  • @Bacco that’s right there worked right :)

  • 1

    @Jorgeb. post there a well simplified version as answer, can be useful to other people!

Show 3 more comments

1 answer

2


What happens is that PHP closes the connection anyway at the end of script, so if we want to check that we are doing everything right we can for example make a select in this same table just below its creation, in the same PHP file (and before the close-up, because 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: Bacchus

  • It would be nice, at the time you can, to add a code snippet neither simplified, but that works, to serve as an example. : ) I appreciate, but do not need the credit no, I just gave the tip.

  • Done, of course you need credit :)

Browser other questions tagged

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