
mysqli 재연결은 PHP 5.5.0 버전부터 지원됩니다. mysqli.reconnect 함수를 사용하여 데이터베이스와의 연결을 재establish하는 것은 가능합니다.
mysqli.reconnect 함수는 현재 연결된 데이터베이스에 대한 연결을 재establish합니다. 이 함수를 호출하면, MySQL 서버와의 연결이 끊어졌을 때 자동으로 재연결이 이루어집니다.
재연결이 성공적으로 이루어질 경우, MySQL 서버와의 연결이 성공적으로 재establish됩니다.
재연결이 실패할 경우, MySQL 서버와의 연결이 실패한 경우에 따라서 다음과 같은 오류 메시지가 출력될 수 있습니다.
- MySQL 서버가 접속할 수 없는 경우: "mysqli::reconnect(): MySQL server has gone away"
- MySQL 서버가 접속할 수 없는 경우: "mysqli::reconnect(): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond."
- MySQL 서버와의 연결이 이미 존재하는 경우: "mysqli::reconnect(): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond."
mysqli.reconnect 함수를 사용하여 데이터베이스와의 연결을 재establish하는 예제는 다음과 같습니다.
#hostingforum.kr
php
$mysqli = new mysqli("localhost", "username", "password", "database");
if ($mysqli->connect_error) {
die("Connection failed: " . $mysqli->connect_error);
}
$mysqli->reconnect();
if ($mysqli->connect_error) {
die("Reconnection failed: " . $mysqli->connect_error);
}
mysqli.reconnect 함수를 사용하여 데이터베이스와의 연결을 재establish하는 것은 PHP 5.5.0 버전부터 지원됩니다. 이 함수를 호출하면, MySQL 서버와의 연결이 끊어졌을 때 자동으로 재연결이 이루어집니다.
2025-04-08 09:54