나는 안드로이드 애플리케이션을 만들고있다. 응용 프로그램이 종료 될 때마다 GCM 등록 ID를 데이터베이스에 삽입하지만 단일 GCM 등록 ID를 두 번 이상 삽입 할 필요가 없습니다.MySQL 데이터베이스에 중복 데이터가 삽입되는 것을 방지하는 방법
MySQL 데이터베이스에 중복 데이터가 삽입되는 것을 방지하려면 어떻게해야합니까?
<?php
// response json
$json = array();
/**
* Registering a user device
* Store reg id in users table
*/
if (isset($_POST["name"]) && isset($_POST["email"]) && isset($_POST["regId"])) {
$name = $_POST["name"];
$email = $_POST["email"];
$gcm_regid = $_POST["regId"]; // GCM Registration ID
// Store user details in db
include_once './db_functions.php';
include_once './GCM.php';
$db = new DB_Functions();
$gcm = new GCM();
$res = $db->storeUser($name, $email, $gcm_regid);
$registatoin_ids = array($gcm_regid);
$message = array("product" => "shirt");
$result = $gcm->send_notification($registatoin_ids, $message);
echo $result;
} else {
// user details missing
}
?>
가능한 복제본 [행이 MySQL 테이블에 있는지 테스트하는 가장 좋은 방법] (http://stackoverflow.com/questions/1676551/best-way-to-test-if-a-row-exists-in -a-mysql-table) – Ohgodwhy