Posted By

terataz on 10/01/11


Tagged

csv active supplier


Versions (?)

Check Supplier and If Active


 / Published in: PHP
 

  1. <?php
  2. //script per il controllo del supplier e verifica se le songs sono ancora attive
  3.  
  4. $db_host = "soundreef.cgwpjynqhrxz.eu-west-1.rds.amazonaws.com";
  5. $db_username = "dbuser";
  6. $db_password = "yatudob";
  7. $db_name = "soundreef";
  8.  
  9.  
  10. mysql_connect("$db_host","$db_username","$db_password") or die("Sorry we could not connect to our database.");
  11. mysql_select_db("$db_name") or die("No database");
  12.  
  13. $fileCont = join('', file('totale song scelte.csv'));
  14. $fileArrN = explode("\n", $fileCont);
  15.  
  16. $a = 0;
  17. foreach ($fileArrN as $value){
  18. $fileArrSemi[$a] = explode(";", $value);
  19. $a++;
  20. }
  21.  
  22.  
  23. $csv='';
  24. $not_found='';
  25.  
  26. for($i = 0; $i < sizeof($fileArrSemi); $i++){
  27. $artist = mysql_real_escape_string(trim($fileArrSemi[$i][0],"\""));
  28. $title = mysql_real_escape_string(trim($fileArrSemi[$i][1],"\""));
  29. $artist_trimmed = trim($artist);
  30. $title_trimmed = trim($title);
  31. $q="SELECT active, supplier_id, artist, title from song where TRIM(title) like '".$title_trimmed."' and TRIM(artist) like '".$artist_trimmed."'";
  32.  
  33.  
  34. $r=mysql_query($q);
  35. $result=mysql_fetch_row($r);
  36. $csv .= $result[0].";".$result[1].";".$artist_trimmed.";".$title_trimmed."\n";
  37.  
  38. }
  39. $file=fopen("result.csv",w);
  40. fwrite($file,$csv);
  41. fclose($file);
  42.  
  43. $file=fopen("notfound.csv",w);
  44. fwrite($file,$not_found);
  45. fclose($file);
  46.  
  47. ?>
  48.  
  49.  
  50. ?>

Report this snippet  

You need to login to post a comment.