I am trying to figure out the proper way to run more than one database query in one script.
Here’s the database connection for the script:
$mysqli = new mysqli("host", "user", "pass", "db_name");
For example, if I want to run a query on the Games table it might look something like this:
$query = "SELECT * FROM Games";
$result = $mysqli->query($query);
while($row = $result -> fetch_array())
{
$rows[] = $row;
}
In the same script if I wanted to run a query on the Teams table it might look something like this:
$query = "SELECT * FROM Teams";
$result = $mysqli->query($query);
while($row = $result -> fetch_array())
{
$rows[] = $row;
}
Since the $mysqli variable is the name of the database connection I can use the same variable name for both queries.
However, it is the rest of the variables that I am wondering about.
Question 1. Can I just rename the $row variable in the second query to $teams_row OR do I need to rename all of the variables like from $query to $teams_query and $result to $teams_result?
Also, the PHP Manual says to free the result at the end of the script.
$result->free();
If I use two different variables for the results (i.e. $game_result and $team_result) I need to free the result for each result set.
However, if I use the $result var for both queries -
Question 2. Do I need to use $result->freeCOLOR=“#006400”[/COLOR]; after each query?
Thanks.