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

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

WBOY
Release: 2016-06-23 13:06:57
Original
886 people have browsed it

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


回复讨论(解决方案)

可以一次插入多条,提高效率
例如多条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);  
Copy after login


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

我试一下,谢谢你

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template