Why should we close the MySQL database after the query command?

I am a starter.

I want to know what will happen if we do not close the MySQL connection.

1- Is it possible to open several databases if we do not close them? I mean, can we open several databases at the same time?

2. Does the closing base increase speed?

3. Is it necessary to close the database or not?

Take a look at this code. I do not use "mysql_close ()", so I do not close the database after each request. There are a lot of requests to this PHP page. Maybe 50,000 per minute. I want to know that this code requires a closing database or not?

<?php   
//Include the file that lets us to connect to the database.
include("database/connection.php");

//Call "connect" function to connect to the database.
connect("database", "localhost", "root", "", "user");

//The GPRS module send a string to this site by GET method. The GPRS user a variable named variable to send the string with.
$received_string = $_GET["variable"];

//Seprates data in an array.
$array_GPRS_data = explode(",", $received_string);

//we need to remove the first letter.
$array_GPRS_data[9] = substr($array_GPRS_data[9], 1);


$array_GPRS_data[13] = substr($array_GPRS_data[13], 4, 2).substr($array_GPRS_data[13], 2, 2).substr($array_GPRS_data[13], 0, 2);

//Query statement.
$query = "INSERT INTO $array_GPRS_data[17](signal_quality, balance, satellite_derived_time, satellite_fix_status, latitude_decimal_degrees,
latitude_hemisphere, longitude_decimal_degrees, longitude_hemisphere, speed, bearing, UTCdate, theChecksum)
VALUES('$array_GPRS_data[0]', '$array_GPRS_data[1]', '$array_GPRS_data[5]', '$array_GPRS_data[6]', '$array_GPRS_data[7]',
'$array_GPRS_data[8]', '$array_GPRS_data[9]', '$array_GPRS_data[10]', '$array_GPRS_data[11]', '$array_GPRS_data[12]', '$array_GPRS_data[13]',
'$array_GPRS_data[16]')";

//Run query.
$result = mysqli_query($query);

//Check if data are inserted in the database correctly.
if($result)
{
    echo("*#01");
}
else
{
    echo("Error: 001");
    echo (mysqli_error());
}   
?>
+4
source share
2
  • , . , . , "" (.. ) , , .
  • ... , , , PHP . , ( ). , .
  • , . (.. 100 , , , ). , , , .
+11

. script.

+3

All Articles