PHP CSV Import Database

Source: Internet
Author: User
Tags bulk insert import database
dudaoruconfig.php page

 
  $csv _key_name) {            $result _arr[$i] [$csv _key_name] = $data _line[$csv _key_num];        }        $i + +;    }    return $result _arr;}? >

dodaoru.php

dodaoru2.php

 
  

dodaoru3.php

 $table _real_column_name) {if ($j = = count ($table _real_column_name_arr)) {$csv _line_data_value. = "'". $r esult_arr[$i] [$csv _real_key_name]. "'        ";        }else{$csv _line_data_value. = "'". $result _arr[$i] [$csv _real_key_name]. "',";    } $j + +; } $all _insert_data_value_str. = "($csv _line_data_value),";} $all _insert_data_value_str = substr ($all _insert_data_value_str,0,-1); Remove the last comma//piece together all field names that need to be inserted into a long string of SQL statements $all_insert_column_name_str = ""; $i = 1;foreach ($table _real_column_name_arr As $csv _real_key_name=> $table _real_column_name) {if ($i = = count ($table _real_column_name_arr)) {$all _insert_co    Lumn_name_str. = "$table _real_column_name";    }else{$all _insert_column_name_str. = "$table _real_column_name,"; } $i + +;} Issue, 1 text in the case of a carriage return result in a string with escape character import failed, 2 garbled//Execute batch INSERT, CSV import complete $query = mysql_query ("INSERT into $tableName ($all _insert_ COLUMN_NAME_STR) values $all _insert_data_value_str ");//BULK INSERT in Datasheet fclose ($csv _file); if ($query) {ECho ' Import succeeded! ';} else{echo ' Import failed! ';}? >

dodaoruajax.php

 
  
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.