-
Notifications
You must be signed in to change notification settings - Fork 0
/
JASEnglishDAO.class.php
77 lines (71 loc) · 2.16 KB
/
JASEnglishDAO.class.php
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
<?php
include_once 'db.class.php';
include_once 'Tool.php';
include_once 'rediska.config.php';
class JASEnglish {
static function insertNewWord ($english,$chinese,$example){
$mysqli = DB::getConn();
$sql = "insert into english(english,chinese,example,created_at) values('{$english}','{$chinese}','{$example}',now())";
JTool::println($sql);
$mysqli->query($sql);
$flag = DB::printError($mysqli);
$sql = "select * from english where id = (select max(id) from english);";
$result = $mysqli -> query($sql);
$arr = $result->fetch_assoc();
$key = new Rediska_Key("allEnglish");
if($allenglish = $key->getValue()) {
$allenglish[]=$arr;
$key->setValue($allenglish);
}
DB::close($mysqli,null,$result);
return $flag;
}
static function getAll (){
$key = new Rediska_Key("allEnglish");
//var_dump($key->getValue());
if($allenglish = $key->getValue()) {
//echo "from redis";
return $allenglish;
}else{
$mysqli = DB::getConn();
$sql = "select * from english";
$result = DB::getResult($sql, $mysqli);
$arr = array();
while($array = $result -> fetch_assoc()){
$arr[] = $array;
}
$key->setValue($arr);
$key->expire(60*60);
DB::close($mysqli,null,$result);
//echo "from db";
return $arr;
}
}
static function getChinese($english) {
$mysqli = DB::getConn();
$sql = "select * from english where english = '{$english}'";
$result = DB::getResult($sql, $mysqli);
$arr = array();
while($array = $result -> fetch_assoc()){
$arr[] = $array;
}
DB::close($mysqli,null,$result);
return $arr;
}
static function update($id,$english,$chinese,$example){
$mysqli = DB::getConn();
$sql = "update from english set english={$english} chinese={$chinese} example={$example} created_at=now() where id={$id}";
$mysqli->query($sql);
}
static function getFromEnglish($english) {
$mysqli = DB::getConn();
$sql = "select * from english where english='{$english}'";
$result = DB::getResult($sql, $mysqli);
$arr = array();
while($array = $result -> fetch_assoc()){
$arr[] = $array;
}
DB::close($mysqli,null,$result);
return $arr;
}
}