2014-04-19 2 views
1

나는 안드로이드 애플리케이션을 만들고있다. 응용 프로그램이 종료 될 때마다 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 
} 
?> 
+2

가능한 복제본 [행이 MySQL 테이블에 있는지 테스트하는 가장 좋은 방법] (http://stackoverflow.com/questions/1676551/best-way-to-test-if-a-row-exists-in -a-mysql-table) – Ohgodwhy

답변

0

내가 일반적으로하는 것은 행이 있는지 없는지를 알아내는 것입니다. 그렇다면 행을 업데이트하고 그렇지 않으면 삽입합니다.

0

중복 된 데이터를 열에 입력하지 않으려면 해당 열을 고유하게 만드십시오.

관련 문제