Jump to content

[SOLVED] PHP Close Connection after every query?


limitphp

Recommended Posts

In my code I have:

a query and a result, and then I grab everything I need from the database.  Later on down the page, I have to do another query, etc.

Do I need to close the database connection or anything before I start the next query?

 

in other words, can I have:

$query = "some query statement";
$result = mysql_query($query);
$data = mysql_fetch_assoc($result);
.
.
.
$query = "some other query statement'";
$result = mysql_query($query);
$data = mysql_fetch_assoc($result);

 

Can both variables be called $query, or do I need to start a new name for the next query, like $query2, $result2, $data2?

 

 

Do I need to close the database connection or anything before I start the next query?

 

No.

 

Can both variables be called $query, or do I need to start a new name for the next query, like $query2, $result2, $data2?

 

I'm almost positive you can keep the variable names the same because you're reassigning the values.  I would rename them because this could cause issues and it's better to assign descriptive names, just like any other variable, so you can refer to them later.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.