mysql connect 해제 관련 정보
mysql connect 해제 관련본문
function db_connect() {
$result = new mysqli('localhost', '****', '****', '****');
if (!$result) {
throw new Exception('Could not connect to database server');
} else {
return $result;
}
}
$conn = db_connect();
$result = $conn->query("update tour_popup
set title = '".$title."'
,memo = '".$memo."'
,open_yn = '".$open_yn."'
,width = ".$width."
,height = ".$height."
,pos_x = ".$pos_x."
,pos_y = ".$pos_y."
where idx = ".$idx." ");
이렇게 실행하고 난 후에
이 구문을 반드시 써줘야되나요?
원랜 반드시 써줘야 리소스 낭비를 막는다고 알고있는데, 전에 어떤분이
$conn->query 이런식으로 사용하면
실행 후 굳이 해제 구문을 안써도 자동으로 해제된다고 들은것 같아서요.
$result = new mysqli('localhost', '****', '****', '****');
if (!$result) {
throw new Exception('Could not connect to database server');
} else {
return $result;
}
}
$conn = db_connect();
$result = $conn->query("update tour_popup
set title = '".$title."'
,memo = '".$memo."'
,open_yn = '".$open_yn."'
,width = ".$width."
,height = ".$height."
,pos_x = ".$pos_x."
,pos_y = ".$pos_y."
where idx = ".$idx." ");
이렇게 실행하고 난 후에
/* 결과를 파괴하고 사용된 메모리를 풀어준다
*/
$result->close();
}
$result->close();
}
/* 접속 닫기 */
$mysqli->close();
$mysqli->close();
이 구문을 반드시 써줘야되나요?
원랜 반드시 써줘야 리소스 낭비를 막는다고 알고있는데, 전에 어떤분이
$conn->query 이런식으로 사용하면
실행 후 굳이 해제 구문을 안써도 자동으로 해제된다고 들은것 같아서요.
추천
0
0
댓글 3개

php의 실행이 종료되면 mysqli 연결도 끊어집니다.
http://php.net/manual/en/mysqli.quickstart.connections.php
By default, every database connection opened by a script is either explicitly closed by the user during runtime or released automatically at the end of the script.
(번역 : 기본적으로 스크립트에 의해 열려진 모든 데이터베이스 연결은 실행시간중 사용자에 의해 명시적으로 닫히거나, 스크립트의 종료시점에서 자동적으로 해제됩니다.)
http://php.net/manual/en/mysqli.quickstart.connections.php
By default, every database connection opened by a script is either explicitly closed by the user during runtime or released automatically at the end of the script.
(번역 : 기본적으로 스크립트에 의해 열려진 모든 데이터베이스 연결은 실행시간중 사용자에 의해 명시적으로 닫히거나, 스크립트의 종료시점에서 자동적으로 해제됩니다.)
감사합니다.
메모리를 비우거나 연결을 종료는 특별히 큰 데이터나 오랜 실행시간이 아니면 별 상관 없습니다^^