Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. <?php
  2. if(isset($_POST['table'])&&isset($_POST['csv']))
  3. {
  4. $table=$_POST['table'];
  5. $file=$_POST['csv'];
  6. $cons= mysqli_connect("127.0.0.1", "database","password","table_name") or die(mysql_error());
  7.  
  8. $result1=mysqli_query($cons,"select count(*) count from $table");
  9. $r1=mysqli_fetch_array($result1);
  10. $count1=(int)$r1['count'];
  11. if (mysqli_connect_errno()) {
  12. echo "CONNECTION Failed. Contact Administrator.";
  13. }
  14.  
  15. $loadFile = mysqli_query($cons, '
  16. LOAD DATA LOCAL INFILE ''.$file.''
  17. INTO TABLE '.$table.'
  18. FIELDS TERMINATED BY ','
  19. LINES TERMINATED BY 'n'
  20. (field_1,field_2 , field_3)
  21. ');
  22.  
  23. $result2=mysqli_query($cons,"select count(*) count from $table");
  24. $r2=mysqli_fetch_array($result2);
  25. $count2=(int)$r2['count'];
  26. echo("Count: ".$count2." ".$count1);
  27.  
  28. $count=$count2-$count1;
  29. if($count>0){
  30. echo "Success";
  31.  
  32. echo "<b> total $count records have been added to the table $table </b> ";
  33. }
  34. else{
  35.  
  36. echo "Failed";
  37. }
  38.  
  39. }
  40. else{
  41. echo "Table name and File name including the .csv filename extension are required";
  42. }
  43.  
  44. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement