How does php insert 1000 pieces of data into mysql?

Source: Internet
Author: User
Php inserts 1000 data records into mysql. how can this problem be solved ??? For ($ i1; $ I & lt; 1000; $ I ++) {& nbsp; $ id. php inserts 1000 pieces of data into mysql. how to write ???
For ($ I = 1; $ I <= 1000; $ I ++)
{
USD id = "100 ";
$ Username = "xm ";

$ SQL = "insert into tb_user (id, username) values ('$ ID',' $ username ')";
Mysql_query ($ SQL );
}


I didn't set id and username as the primary key,

But insert a piece of data. what is the problem? Thank you!

------ Solution --------------------
Do not operate databases frequently. Suggestions

PHP code
For ($ I = 1; $ I <= 1000; $ I ++) {$ id = '000000'; $ username = 'xm '; $ SQL [] = '('. $ id. ',"'. $ username. '")';} mysql_query ('Insert into tb_user (id, username) values '. implode (',', $ SQL ));

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.