-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql-test.php
More file actions
213 lines (173 loc) · 4.47 KB
/
Copy pathsql-test.php
File metadata and controls
213 lines (173 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php
require_once('vendor/autoload.php');
$faker = Faker\Factory::create();
$db = new PDO('mysql:host=localhost;dbname=mydatabase77', 'tfgi', 'azerty');
$db->query("
DELETE FROM invoices;
DELETE FROM commands;
DELETE FROM carts;
DELETE FROM shoplists;
DELETE FROM photos;
DELETE FROM rates;
DELETE FROM payements;
DELETE FROM addresses;
DELETE FROM users;
DELETE FROM products;
ALTER TABLE users AUTO_INCREMENT = 1;
ALTER TABLE products AUTO_INCREMENT = 1;
ALTER TABLE rates AUTO_INCREMENT = 1;
ALTER TABLE photos AUTO_INCREMENT = 1;
ALTER TABLE shoplists AUTO_INCREMENT = 1;
ALTER TABLE commands AUTO_INCREMENT = 1;
ALTER TABLE invoices AUTO_INCREMENT = 1;
");
$counter=0;
for ($i = 0; $i = 100; $i++) {
$hash = password_hash($faker->password, PASSWORD_DEFAULT);
$db->query("INSERT INTO users (
User_FirstName,
User_LastName,
User_Phone,
User_Email,
User_Password
)
VALUES(
'{$faker->firstName()}',
'{$faker->lastName()}',
'{$faker->phoneNumber}',
'{$faker->email}',
'{$hash}'
);
");
$user_id = $db->lastInsertId(); //recupere le user_id
$db->query("INSERT INTO products (
Product_Name,
Product_Description,
Product_Type,
Product_Price,
Product_NumberLeft,
Product_TotalRate
)
VALUES(
'{$faker->domainWord}',
'{$faker->text()}',
'{$faker->colorName}',
'{$faker->randomNumber()}',
'{$faker->randomNumber()}',
'{$faker->numberBetween(0, 5)}'
);
");
$product_id = $db->lastInsertId(); //recupere le product id
$db->query("INSERT INTO addresses (
User_Id,
Address_Address,
Address_CityName,
Address_PostalCode,
Address_State,
Address_Country
)
VALUES(
'{$user_id}',
'{$faker->address}',
'{$faker->city}',
'{$faker->postcode}',
'{$faker->state}',
'{$faker->country}'
);
INSERT INTO payements (
User_Id,
Payement_CartNumber,
Payement_ExpirationDate,
Payement_Name,
Payement_SafeCode
)
VALUES(
'{$user_id}',
'{$faker->randomNumber()}',
'{$faker->date($format = 'Y-m-d', $max = 'now')}',
'{$faker->lastName()}',
'{$faker->randomNumber()}'
);
");
$counter+= 1;
$user_id_rand = $faker->numberBetween(1, $counter);
$product_id_rand = $faker->numberBetween(1, $counter);
$db->query("INSERT INTO rates (
User_Id,
Product_Id,
Rate_Rate
)
VALUES(
'{$user_id_rand}',
'{$product_id_rand}',
'{$faker->numberBetween(0, 5)}'
);
");
$randbool = $faker->numberBetween(1, 2);
echo $randbool;
$blob = $faker->city . '.jpeg';
if ($randbool > 1) {
$db->query("INSERT INTO photos (
User_Id,
Photo_photo
)
VALUES(
'{$user_id_rand}',
'{$blob}'
);
");
} else {
$db->query("INSERT INTO photos (
Product_Id,
Photo_photo
)
VALUES(
'{$product_id_rand}',
'{$blob}'
);
");
}
$db->query("INSERT INTO shoplists (
User_Id
)
VALUES(
'{$user_id}'
);
");
$shoplist_id = $db->lastInsertId(); //recupere le shoplist id
$shoplist_id_rand = $faker->numberBetween(1, $counter);
$mydate = $faker->date($format = 'Y-m-d', $max = 'now');
$db->query("INSERT INTO carts (
Shoplist_Id,
Product_Id,
Cart_Total,
Cart_ProductCount
)
VALUES(
'{$shoplist_id_rand}',
'{$product_id_rand}',
'{$faker->numberBetween(5, 500)}',
'{$faker->numberBetween(0, 36)}'
);
");
$db->query("INSERT INTO commands (
Shoplist_Id,
Command_OrderDate
)
VALUES(
'{$shoplist_id}',
'{$mydate}'
);
");
$command_id = $db->lastInsertId(); //recupere le command id
$db->query("INSERT INTO invoices (
Command_Id,
Invoice_Date
)
VALUES(
'{$command_id}',
'{$faker->date($format = 'Y-m-d', $max = 'now')}'
);
");
}
?>