Import CSV big file data into MYSQL database using PHP

Source: Internet
Author: User
More than once, my colleagues asked me the same question. here is the simplest PHP implementation. If you have a better method, share the following code: [php] & lt ;? Php $ db_host & quot; 192.168.1.10 & quot; $ db_user & quot; root & quot; $ db_psw & quot; 11111 & quot; $ db_name & q


More than once, my colleagues asked me the same question. here is the simplest PHP implementation. If you have a better method, please share with us :)

The code is as follows:
[Php]
$ Db_host = "192.168.1.10 ";
$ Db_user = "root ";
$ Db_psw = "11111 ";
$ Db_name = "csvimport ";
 
$ Conn = mysql_connect ($ db_host, $ db_user, $ db_psw) or die ("Connection occur error ");
Mysql_select_db ($ db_name, $ conn) or die ("Connection occur error ");
Mysql_query ("set names UTF-8 ");
 
 
Mysql_query ("load data infile '/root/bill20120813121249.csv 'into TABLE 'billdata' fields terminated ', 'enabled by' \ "'elasticed by' \" 'lines TERMINATED by' \ r \ n' IGNORE 1 LINES; ") or die ('Error :'. mysql_error ());
 
?>

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.