A question about when to close mysql query in php
Get the solution ↓↓↓A question about when to close mysql query.
Hello, I have two cases to decide whether I should close the mysql query.
First case, I know I should close this query.
But for the second case, should I also close the query as the same as the first case?
first case
~code
$result = $conn->query($query);
if(!$result) {
die("Invalid");
}
$rows = $result->num_rows;
$password = sanitizeString($_SERVER['PHP_AUTH_PW']);
for($i = 0; $i < $rows; $i++){
$result->data_seek($i);
$row = $result->fetch_array(MYSQLI_ASSOC);
$salt1 = $row['1'];
$salt2 = $row['2'];
$hashtoken = $row['pass'];
$admin = $row['username'];
$result->close(); // here
}
second case
$query = "INSERT INTO storage (name, content) VALUES ('$file_name', '$content')";
$result = $conn->query($query);
if (!$result) {
die("error");
} else {
echo "Uploaded! <br>";
}
$result->close(); // here
Answer
Solution:
It is very important to close mysql connection after every request.
On your given first case you should close your mysql connection after end of for syntax.
Your second case is fine.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: illuminate\http\exceptions\posttoolargeexception
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.