Advertisement
Guest User

Untitled

a guest
Nov 17th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. device_id(field)
  2. 123asf15fas
  3. 456g4fd45ww
  4. 7861fassd45
  5.  
  6. ...
  7. $q = "INSERT INTO $database.$table `device_id` VALUES $device_id";
  8. $result = mysql_query($q);
  9. ...
  10.  
  11. <?php
  12. // YOUR MYSQL DATABASE CONNECTION
  13. $hostname = 'localhost';
  14. $username = 'root';
  15. $password = '';
  16.  
  17. $database = 'device';
  18. $table = 'device_id';
  19. $db_link = mysql_connect($hostname, $username, $password);
  20. mysql_select_db( $database ) or die('ConnectToMySQL: Could not select database: ' . $database );
  21. //$result = ini_set ( 'mysql.connect_timeout' , '60' );
  22.  
  23. $device_id = $_GET["device_id"];
  24. $q = "REPLACE INTO $database.$table (`device_id`) VALUES ($device_id)";
  25. $result = mysql_query($q);
  26. if (!$result) {
  27. die('Invalid query: ' . mysql_error());
  28. }
  29. ?>
  30.  
  31. SELECT * FROM `your_table` WHERE `device_id`='123asf15fas'
  32.  
  33. $result = mysql_query("SELECT * FROM `your_table` WHERE `device_id`='123asf15fas'");
  34. if (!$result)
  35. {
  36. // your code INSERT
  37. $result = mysql_query("INSERT INTO $database.$table `device_id` VALUES $device_id");
  38. }
  39.  
  40. ALTER TABLE `your_table` ADD UNIQUE (`device_id`)
  41.  
  42. #1062 - Duplicate entry '1' for key 'PRIMARY'
  43.  
  44. REPLACE INTO $database.$table SET device_id = $device_id;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement