Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(isset($_POST['table'])&&isset($_POST['csv']))
- {
- $table=$_POST['table'];
- $file=$_POST['csv'];
- $cons= mysqli_connect("127.0.0.1", "database","password","table_name") or die(mysql_error());
- $result1=mysqli_query($cons,"select count(*) count from $table");
- $r1=mysqli_fetch_array($result1);
- $count1=(int)$r1['count'];
- if (mysqli_connect_errno()) {
- echo "CONNECTION Failed. Contact Administrator.";
- }
- $loadFile = mysqli_query($cons, '
- LOAD DATA LOCAL INFILE ''.$file.''
- INTO TABLE '.$table.'
- FIELDS TERMINATED BY ','
- LINES TERMINATED BY 'n'
- (field_1,field_2 , field_3)
- ');
- $result2=mysqli_query($cons,"select count(*) count from $table");
- $r2=mysqli_fetch_array($result2);
- $count2=(int)$r2['count'];
- echo("Count: ".$count2." ".$count1);
- $count=$count2-$count1;
- if($count>0){
- echo "Success";
- echo "<b> total $count records have been added to the table $table </b> ";
- }
- else{
- echo "Failed";
- }
- }
- else{
- echo "Table name and File name including the .csv filename extension are required";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement