Advertisement
Guest User

Untitled

a guest
Nov 29th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet
  2. -> LINES TERMINATED BY 'rn';
  3.  
  4. INSERT INTO yourtable VALUES (1,2), (5,5), ...
  5.  
  6. $file = file("content.txt"); //read file line by line
  7. foreach ($file as $val) {
  8. if (trim($val) != '') { //ignore empty lines
  9. mysql_query("INSERT INTO xxx SET club='" . $val . "'");
  10. }
  11. }
  12.  
  13. <?php
  14. $conn = new PDO($dsn, $username, $password);
  15. $stmt = $conn->prepare('INSERT INTO table VALUES (NULL, ?)');
  16. foreach(file('list.txt') as $club) {
  17. $stmt->execute(array($club));
  18. }
  19.  
  20. <?php
  21. $servername = "localhost";
  22. $username = "user";
  23. $password = "pass";
  24. $dbname = "db";
  25. // Create connection
  26. $conn = new mysqli($servername, $username, $password, $dbname);
  27. // Check connection
  28. if ($conn->connect_error) {
  29. die("Connection failed: " . $conn->connect_error);
  30. }
  31. $file = file("list.txt"); //read file line by line
  32. foreach ($file as $val) {
  33. if (trim($val) != '') { //ignore empty lines
  34. $sql = "INSERT INTO `db`.`table` (`column`) VALUES ('$val');";
  35. if ($conn->query($sql) === TRUE) {
  36. echo "New record created successfully";
  37. } else {
  38. echo "Error: " . $sql . "<br>" . $conn->error;
  39. }
  40. }
  41. }
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement