Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = 'root';//database user variable
  4. $password = "MontanaNet4**";//database user password variable
  5.  
  6. //load sm list file:
  7. $array = array(); // this is the array for the data from siteList.txt will be stored.
  8. $handle = fopen("nodeList.txt", "r") or die("epic fail");
  9.  
  10. while(($row = fgetcsv($handle, 1000, ",")) !== FALSE) {
  11. $array[$row[0]] = $row[0];
  12. }
  13. fclose($handle);
  14.  
  15.  
  16. //display ammount of sites loaded in the array
  17. echo "there is ". count($array) . " nodes loaded" . "<br>";
  18.  
  19. sort($array);
  20.  
  21. foreach($array as $key => $NodeName){
  22.  
  23. try {
  24. $conn = new PDO("mysql:host=$servername;dbname=adatabase", $username, $password);
  25. // set the PDO error mode to exception
  26. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  27.  
  28. $sql = "INSERT INTO `node`(,`NodeName`) VALUES (, :NodeName);";
  29. //INSERT INTO `nodecounts`(`NodeID`,`aCount`,`DateLogged`) VALUES (:NodeId, :aCount, :DateLogged);
  30. //";
  31. // prepare sql and bind parameters
  32. $stmt = $conn->prepare($sql);
  33.  
  34. //$stmt->bindParam(':ID', $id);
  35. $stmt->bindParam(':NodeName', $NodeName);
  36. //$stmt->bindParam(':NodeID', $NodeID);
  37. //$stmt->bindParam(':aCount', $aCount);
  38. //$stmt->bindParam(':DateLogged', $DateLogged);
  39. $stmt->execute();
  40.  
  41. }
  42. catch(PDOException $e)
  43. {
  44. echo "Connection failed: " . $e->getMessage();
  45. }
  46. }//end foreach
  47. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement