Skip to content

Commit 0484608

Browse files
committed
More test case.
1 parent 6d0fece commit 0484608

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ $DB->closeConnection();
245245
Iterator
246246
------------
247247

248-
Use iterators when you want to read thousands of data from the database for full update of Elastic Search or Solr.
248+
**Use an iterator** when you want to read thousands of data from the database for statistical or full update of Elastic Search or Solr indexes.
249249

250250
An iterator is a traversable object that does not read all the data queried from MySQL into memory.
251251

@@ -264,4 +264,14 @@ foreach($it as $key => $value) {
264264
sendDataToElasticSearch($key, $value);
265265
$colorCountMap[$value['color']]++;
266266
}
267+
var_export($colorCountMap);
268+
```
269+
Return:
270+
271+
```php
272+
array(3) {
273+
[red] => 2
274+
[yellow] => 2
275+
[green] => 1
276+
}
267277
```

test.php

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
<?php
2+
if (PHP_SAPI !== "cli") {
3+
header('HTTP/1.1 403 Forbidden');
4+
exit('error: 403 Access Denied');
5+
}
6+
7+
if (PHP_OS === "WINNT") {
8+
exec('chcp 65001');
9+
}
10+
211
$mTime = explode(' ', microtime());
312
$startTime = $mTime[1] + $mTime[0];
413

@@ -29,6 +38,18 @@
2938

3039
var_dump($AffectedRows);
3140

41+
var_export($DB->query("SELECT * FROM fruit WHERE name=:name and color=:color",array('name'=>'apple','color'=>'red')));
42+
43+
var_export($DB->query("SELECT * FROM fruit WHERE name IN (?)",array('apple','banana')));
44+
45+
var_export($DB->column("SELECT color FROM fruit WHERE name IN (?)",array('apple','banana','watermelon')));
46+
47+
var_export($DB->row("SELECT * FROM fruit WHERE name=? and color=?",array('apple','red')));
48+
49+
echo $DB->single("SELECT color FROM fruit WHERE name=? ",array('watermelon'));
50+
51+
52+
3253
$it = $DB->iterator("SELECT * FROM fruit limit 0, 1000000;");
3354
$colorCountMap = array(
3455
'red' => 0,
@@ -37,12 +58,22 @@
3758
);
3859
foreach($it as $key => $value) {
3960
// sendDataToElasticSearch($key, $value);
40-
var_dump($key);
41-
var_dump($value);
61+
var_export($key);
62+
var_export($value);
4263
$colorCountMap[$value['color']]++;
4364
}
44-
var_dump($colorCountMap);
65+
var_export($colorCountMap);
66+
67+
// Delete
68+
$DB->query("DELETE FROM fruit WHERE id = :id", array("id"=>"1"));
69+
$DB->query("DELETE FROM fruit WHERE id = ?", array("1")); // Update
70+
$DB->query("UPDATE fruit SET color = :color WHERE name = :name", array("name"=>"strawberry","color"=>"yellow"));
71+
$DB->query("UPDATE fruit SET color = ? WHERE name = ?", array("yellow","strawberry"));
72+
// Insert
73+
$DB->query("INSERT INTO fruit(id,name,color) VALUES(?,?,?)",array(null,"mango","yellow"));//Parameters must be ordered
74+
$DB->query("INSERT INTO fruit(id,name,color) VALUES(:id,:name,:color)", array("color"=>"yellow","name"=>"mango","id"=>null));//Parameters order free
4575

76+
echo $DB->querycount;
4677

4778
$mTime = explode(' ', microtime());
4879
echo '<br>'.(number_format(($mTime[1] + $mTime[0] - $startTime), 6)*1000).'ms';

0 commit comments

Comments
 (0)