Guest User

Untitled

a guest
Jan 17th, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. CREATE TABLE IF NOT EXISTS `temps_test` (
  2. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  3. `sensor_serial` varchar(64) COLLATE latin1_general_ci DEFAULT NULL,
  4. `temp_c` float DEFAULT NULL,
  5. `dates` datetime DEFAULT NULL,
  6. PRIMARY KEY (`id`),
  7. KEY `date` (`dates`)
  8. )
  9.  
  10. foreach ($output as $k => &$v) {
  11. $sql = "INSERT INTO temps_test (sensor_serial,temp_c,dates) VALUES ('$v[7]','$v[3]','$v[5]') WHERE NOT EXISTS (SELECT * FROM temps_test WHERE sensor_serial='$v[7]' AND dates='$v[5]')";
  12. $go = mysql_query($sql) or die( mysql_error() );
  13. }
  14.  
  15. INSERT INTO temps_test (sensor_serial,temp_c,dates)
  16. VALUES ('val1','val2','val3')
  17. ON DUPLICATE KEY UPDATE sensor_serial=sensor_serial;
  18.  
  19. CREATE TABLE IF NOT EXISTS `temps_test`
  20. (
  21. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  22. `sensor_serial` varchar(64) COLLATE latin1_general_ci DEFAULT NULL,
  23. `temp_c` float DEFAULT NULL,
  24. `dates` datetime DEFAULT NULL,
  25. PRIMARY KEY (`id`),
  26. KEY `date` (`dates`),
  27. CONSTRAINT t_uq INIQUE (`sensor_serial`) -- <== this one
  28. )
Add Comment
Please, Sign In to add comment