Note: This article is from the blog "afei". If you want to reprint this articleArticle, Please contact the author! And indicate the source: http://blog.csdn.net/faye0412/article/details/7886153
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 :)
CodeAs 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 by', 'enabled' \" 'elasticed '\"' Lines terminated by '\ r \ n' ignore 1 lines; ") or die ('error:'. mysql_error ();?>
The above code is just a prototype of implementation. You can improve and improve it as needed.
For more use of load data infile in MySQL, see here: http://dev.mysql.com/doc/refman/5.1/en/load-data.html
Appendix:
If you encounter this problem/exception:
Error: The used command is not allowed with this MySQL version
Modify:
$ DBC = mysql_connect ($ db_host, $ db_user, $ db_psw) or die (_ error15. ":". mysql_error ());
Is:
$ DBC = mysql_connect ($ db_host, $ db_user, $ db_psw,
False, 128) Or die (_ error15. ":". mysql_error ());