connect_error) { die("DB接続エラー"); } $mysqli->set_charset('utf8'); // メッセージ用 $msg = 'NG'; // DB用変数 $db_type = "GET"; if ($_GET['value'] == ""){ $db_value = 0; }else{ $db_value = $_GET['value']; } if ($_GET['string'] == ""){ $db_string = ""; }else{ $db_string = $_GET['string']; } // SQL $sql = "INSERT INTO t_example (type,value,string,reg_date) VALUES(?,?,?,now())"; // トランザクションの開始 if ($mysqli->autocommit(FALSE)){ // プリペアドステートメントの作成 if ($stmt = $mysqli->prepare($sql)) { // マーカにパラメータをバインド(s= string d= double i=integer) if ($stmt->bind_param("sis", $db_type, // type $db_value, // value $db_string // string )){ // 実行 if ($stmt->execute()){ $stmt->close(); // コミット if ($mysqli->commit()) { $msg = 'OK'; // DB登録成功 // ロールバック }else{ $mysqli->rollback(); } } } } } $mysqli->close(); ?>