Home  >  Article  >  Backend Development  >  想实现批量开会员卡,我的思路是用循环向数据库里插入数据,有更好的方法吗?

想实现批量开会员卡,我的思路是用循环向数据库里插入数据,有更好的方法吗?

WBOY
WBOYOriginal
2016-06-23 13:06:57861browse

如题,想实现批量开会员卡,我的思路是用循环向数据库里插入数据,有更好的方法吗?


回复讨论(解决方案)

可以一次插入多条,提高效率
例如多条sql

INSERT INTO `insert_table` (`uid`, `content`, `type`) VALUES ('userid_0', 'content_0', 0);  INSERT INTO `insert_table` (`uid`, `content`, `type`) VALUES ('userid_1', 'content_1', 1);  


可以改为一次插入:
INSERT INTO `insert_table` (`uid`, `content`, `type`) VALUES ('userid_0', 'content_0', 0), ('userid_1', 'content_1', 1);

我试一下,谢谢你

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn