You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$DB->query("INSERT INTO `fruit` (`id`, `name`, `color`) VALUES
145
+
(1, 'apple', 'red'),
146
+
(2, 'banana', 'yellow'),
147
+
(3, 'watermelon', 'green'),
148
+
(4, 'pear', 'yellow'),
149
+
(5, 'strawberry', 'red');
150
+
");
151
+
?>
152
+
<h4>
153
+
Fetching with Bindings (ANTI-SQL-INJECTION):
154
+
</h4>
155
+
<pre>
156
+
<code class="lang-php">
157
+
<?php
158
+
$DB->query("SELECT * FROM fruit WHERE name=? and color=?",array('apple','red'));
159
+
$DB->query("SELECT * FROM fruit WHERE name=:name and color=:color",array('name'=>'apple','color'=>'red'));
160
+
?>
161
+
</code>
162
+
</pre>
163
+
<p>
164
+
Result:
165
+
</p>
166
+
<pre>
167
+
<code class="lang-php">
168
+
<?php
169
+
var_export($DB->query("SELECT * FROM fruit WHERE name=:name and color=:color",array('name'=>'apple','color'=>'red')));
170
+
?>
171
+
</code>
172
+
</pre>
173
+
<h4>
174
+
WHERE IN:
175
+
</h4>
176
+
<pre>
177
+
<code class="lang-php">
178
+
<?php
179
+
$DB->query("SELECT * FROM fruit WHERE name IN (?)",array('apple','banana'));
180
+
?>
181
+
</code>
182
+
</pre>
183
+
<p>
184
+
Result:
185
+
</p>
186
+
<pre>
187
+
<code class="lang-php">
188
+
<?php
189
+
var_export($DB->query("SELECT * FROM fruit WHERE name IN (?)",array('apple','banana')));
190
+
?>
191
+
</code>
192
+
</pre>
193
+
<h4>
194
+
Fetching Column:
195
+
</h4>
196
+
<pre>
197
+
<code class="lang-php">
198
+
<?php
199
+
$DB->column("SELECT color FROM fruit WHERE name IN (?)",array('apple','banana','watermelon'));
200
+
?>
201
+
</code>
202
+
</pre>
203
+
<p>
204
+
Result:
205
+
</p>
206
+
<pre>
207
+
<code class="lang-php">
208
+
<?php
209
+
var_export($DB->column("SELECT color FROM fruit WHERE name IN (?)",array('apple','banana','watermelon')));
210
+
?>
211
+
</code>
212
+
</pre>
213
+
<h4>
214
+
Fetching Row:
215
+
</h4>
216
+
<pre>
217
+
<code class="lang-php">
218
+
<?php
219
+
$DB->row("SELECT * FROM fruit WHERE name=? and color=?",array('apple','red'));
220
+
?>
221
+
</code>
222
+
</pre>
223
+
<p>
224
+
Result:
225
+
</p>
226
+
<pre>
227
+
<code class="lang-php">
228
+
<?php
229
+
var_export($DB->row("SELECT * FROM fruit WHERE name=? and color=?",array('apple','red')));
230
+
?>
231
+
</code>
232
+
</pre>
233
+
<h4>
234
+
Fetching single:
235
+
</h4>
236
+
<pre>
237
+
<code class="lang-php">
238
+
<?php
239
+
$DB->single("SELECT color FROM fruit WHERE name=? ",array('watermelon'));
240
+
?>
241
+
</code>
242
+
</pre>
243
+
<p>
244
+
Result:
245
+
</p>
246
+
<pre>
247
+
<code class="lang-php">
248
+
<?php
249
+
echo$DB->single("SELECT color FROM fruit WHERE name=? ",array('watermelon'));
250
+
?>
251
+
</code>
252
+
</pre>
253
+
<h4>
254
+
Delete / Update / Insert
255
+
</h4>
256
+
<p>
257
+
These operations will return the number of affected result set. (integer)
258
+
</p>
259
+
<pre>
260
+
<code class="lang-php">
261
+
<?php
262
+
// Delete
263
+
$DB->query("DELETE FROM fruit WHERE id = :id", array("id"=>"1"));
264
+
$DB->query("DELETE FROM fruit WHERE id = ?", array("1")); // Update
265
+
$DB->query("UPDATE fruit SET color = :color WHERE name = :name", array("name"=>"strawberry","color"=>"yellow"));
266
+
$DB->query("UPDATE fruit SET color = ? WHERE name = ?", array("yellow","strawberry"));
267
+
// Insert
268
+
$DB->query("INSERT INTO fruit(id,name,color) VALUES(?,?,?)",array(null,"mango","yellow"));//Parameters must be ordered
269
+
$DB->query("INSERT INTO fruit(id,name,color) VALUES(:id,:name,:color)", array("color"=>"yellow","name"=>"mango","id"=>null));//Parameters order free
270
+
?>
271
+
</code>
272
+
</pre>
273
+
<?php
274
+
// Delete
275
+
$DB->query("DELETE FROM fruit WHERE id = :id", array("id"=>"1"));
276
+
$DB->query("DELETE FROM fruit WHERE id = ?", array("1")); // Update
277
+
$DB->query("UPDATE fruit SET color = :color WHERE name = :name", array("name"=>"strawberry","color"=>"yellow"));
278
+
$DB->query("UPDATE fruit SET color = ? WHERE name = ?", array("yellow","strawberry"));
279
+
// Insert
280
+
$DB->query("INSERT INTO fruit(id,name,color) VALUES(?,?,?)",array(null,"mango","yellow"));//Parameters must be ordered
281
+
$DB->query("INSERT INTO fruit(id,name,color) VALUES(:id,:name,:color)", array("color"=>"yellow","name"=>"mango","id"=>null));//Parameters order free
282
+
?>
283
+
<h4>
284
+
Get Last Insert ID
285
+
</h4>
286
+
<pre>
287
+
<code class="lang-php">
288
+
<?php
289
+
$DB->lastInsertId();
290
+
?>
291
+
</code>
292
+
</pre>
293
+
<p>
294
+
Result:
295
+
</p>
296
+
<pre>
297
+
<code class="lang-php">
298
+
ID for array("color"=>"yellow","name"=>"mango","id"=>null):
299
+
<?php
300
+
echo$DB->lastInsertId();
301
+
?>
302
+
</code>
303
+
</pre>
304
+
<h4>
305
+
Get the number of queries since the object initialization
0 commit comments