· 6 years ago · Mar 12, 2019, 06:16 PM
1$conn = mysql_connect('localhost', 'root', '123');
2mysql_select_db('mydb', $conn);
3$time1 = time();
4for ($i=1;$i<500;$i++) {
5mysql_query("Insert into accounts(id, username, email, password) VALUES("$i", "$i","$i",NOW())");
6}
7print time() - $time1; // return ~22
8
9CREATE TABLE IF NOT EXISTS `accounts` (
10 `id` int(11) NOT NULL AUTO_INCREMENT,
11 `username` varchar(20) NOT NULL,
12 `email` varchar(200) NOT NULL,
13 `password` varchar(20) NOT NULL,
14 `status` varchar(10) DEFAULT 'pending',
15 `email_newsletter_status` varchar(3) DEFAULT 'out',
16 `email_type` varchar(4) DEFAULT 'text',
17 `email_favorite_artists_status` varchar(3) DEFAULT 'out',
18 `created_date` datetime DEFAULT NULL,
19 PRIMARY KEY (`id`),
20 UNIQUE KEY `username` (`username`),
21 UNIQUE KEY `email` (`email`)
22) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7500 ;
23
24mysql_query("START TRANSACTION");
25for ($i=1;$i<500;$i++) {
26 mysql_query("Insert into accounts(id, username, email, password) VALUES("$i", "$i","$i",NOW())");
27}
28mysql_query("COMMIT");
29
30INSERT INTO example
31 (example_id, name, value, other_value)
32VALUES
33 (100, 'Name 1', 'Value 1', 'Other 1'),
34 (101, 'Name 2', 'Value 2', 'Other 2'),
35 (102, 'Name 3', 'Value 3', 'Other 3'),
36 (103, 'Name 4', 'Value 4', 'Other 4');
37
38$valStr = "";
39for ($i=1;$i<500;$i++) {
40 $valStr = ($valStr == "" ? "" : ", ") . "('$i', '$i', '$i', NOW())";
41}
42if ($valStr != "") {
43 mysql_query("Insert into accounts(id, username, email, password) VALUES $valStr");
44}