@@ -144,6 +144,43 @@ $db->onDuplicate($updateColumns, $lastInsertId);
144
144
$id = $db->insert ('users', $data);
145
145
```
146
146
147
+ Insert multiple datasets at once
148
+ ``` php
149
+ $data = Array(
150
+ Array ("login" => "admin",
151
+ "firstName" => "John",
152
+ "lastName" => 'Doe'
153
+ ),
154
+ Array ("login" => "other",
155
+ "firstName" => "Another",
156
+ "lastName" => 'User',
157
+ "password" => "very_cool_hash"
158
+ )
159
+ );
160
+ $ids = $db->insertMulti('users', $data);
161
+ if(!$ids) {
162
+ echo 'insert failed: ' . $db->getLastError();
163
+ } else {
164
+ echo 'new users inserted with following id\'s: ' . implode(', ', $ids);
165
+ }
166
+ ```
167
+
168
+ If all datasets only have the same keys, it can be simplified
169
+ ``` php
170
+ $data = Array(
171
+ Array ("admin", "John", "Doe"),
172
+ Array ("other", "Another", "User")
173
+ );
174
+ $keys = Array("login", "firstName", "lastName");
175
+
176
+ $ids = $db->insertMulti('users', $data, $keys);
177
+ if(!$ids) {
178
+ echo 'insert failed: ' . $db->getLastError();
179
+ } else {
180
+ echo 'new users inserted with following id\'s: ' . implode(', ', $ids);
181
+ }
182
+ ```
183
+
147
184
### Replace Query
148
185
<a href =' https://dev.mysql.com/doc/refman/5.0/en/replace.html ' >Replace()</a > method implements same API as insert();
149
186
713
750
echo 'Update failed. Error: '. $db->getLastError();
714
751
```
715
752
716
- ### Query exectution time benchmarking
753
+ ### Query execution time benchmarking
717
754
To track query execution time setTrace() function should be called.
718
755
``` php
719
756
$db->setTrace (true);
0 commit comments