Created
August 24, 2010 03:27
-
-
Save chobie/546876 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
mysqliでコネクションを確認しつつ接続しなおすサンプル | |
*/ | |
$mysqli = mysqli_init(); | |
$mysqli->options(MYSQLI_INIT_COMMAND,"set names utf8"); | |
$host = "localhost"; | |
$user = "user"; | |
$pass = ""; | |
$db_name = "moe"; | |
$mysqli->real_connect($host,$user,$pass,$db_name); | |
$mysqli->query("SET SESSION wait_timeout = 3"); | |
if($error = mysqli_connect_error()){ | |
throw new Exception($error); | |
} | |
$mysqli->set_charset("utf8"); | |
for(;;){ | |
if($mysqli->ping()){ | |
printf ("Our connection is ok!\n"); | |
printf("thread_id:%d\n",$mysqli->thread_id); | |
sleep(4); | |
}else{ | |
$stmt = $mysqli->query("select 1"); | |
printf("thread_id:%d\n",$mysqli->thread_id); | |
printf("Our connection is not good.\n"); | |
$mysqli->real_connect("localhost","websrv","","auction_motekawa"); | |
sleep(3); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment