我想知道如果我們不關閉MySQL連接會發生什麼。
1-如果我們不關閉它們,是否可以打開多個數據庫?我的意思是我們可以在同一時間打開多個數據庫嗎?
2-關閉數據庫是否增加速度?
3-是否需要關閉數據庫或者它是可選的?
看看這段代碼。我不使用「mysql_close()」,所以在每次請求後都不關閉數據庫。這個PHP頁面有很多請求。也許每分鐘50000。我想知道關閉數據庫對於此代碼是否必要或不是?
<?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());
}
?>
http://stackoverflow.com/questions/880885/is-closing-the-mysql-connection-important – CIRCLE
http://stackoverflow.com/questions/336078/php-mysql-when-是最好的時間從數據庫中斷開 – CIRCLE