Repository navigation
Expand file tree
/
Copy pathSiteConfigTable.php
More file actions
109 lines (99 loc) · 3.45 KB
/
Copy pathSiteConfigTable.php
File metadata and controls
109 lines (99 loc) · 3.45 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
<?php
/**
* Created by PhpStorm.
* User: childeYin<尹少爷>
* Date: 16/07/2018
* Time: 5:14 PM
*/
class SiteConfigTable extends BaseTable
{
/**
* @var Wpf_Logger
*/
private $logger;
private $table = "siteConfig";
private $columns = [
"id",
"configKey",
"configValue"
];
public function init()
{
$this->logger = $this->ctx->getLogger();
$this->columns = implode(",", $this->columns);
}
public function insertSiteConfig($configKey, $configValue)
{
$tag = __CLASS__ . "->" . __FUNCTION__;
$sqlStr = "('" . $configKey . "'," . $configValue . ")";
$sql = "insert into
siteConfig(configKey, configValue)
values
$sqlStr;";
try {
$prepare = $this->db->prepare($sql);
$this->handlePrepareError($tag, $prepare);
$result = $prepare->execute();
return $result;
} finally {
$this->logger->writeSqlLog($tag, $sql, [$configKey, $configValue], $this->getCurrentTimeMills());
}
}
public function updateSiteConfig($configKey, $configValue)
{
$tag = __CLASS__ . "->" . __FUNCTION__;
try {
$tag = __CLASS__ . "->" . __FUNCTION__;
$sql = "update $this->table set configValue=:configValue where configKey=:configKey;";
$prepare = $this->db->prepare($sql);
$this->handlePrepareError($tag, $prepare);
$prepare->bindValue(":configValue", $configValue);
$prepare->bindValue(":configKey", $configKey);
$result = $prepare->execute();
$count = $prepare->rowCount();
if ($result && $count > 0) {
return true;
}
} finally {
$this->ctx->Wpf_Logger->writeSqlLog($tag, $sql, [$configKey, $configValue], $this->getCurrentTimeMills());
}
return false;
}
/**
* @param bool $configKey
* @return array
*/
public function selectSiteConfig($configKey = false)
{
$tag = __CLASS__ . "_" . __FUNCTION__;
try {
$startTime = microtime(true);
if ($configKey === false) {
$sql = "select $this->columns from $this->table;";
} elseif (is_string($configKey)) {
$sql = "select $this->columns from $this->table where configKey=:configKey;";
} elseif (is_array($configKey)) {
$configKeyStr = implode("','", $configKey);
$sql = "select $this->columns from $this->table where configKey in ('$configKeyStr');";
}
$prepare = $this->dbSlave->prepare($sql);
$this->handlePrepareError($tag, $prepare);
if ($configKey !== false && is_string($configKey)) {
$prepare->bindValue("configKey", $configKey);
}
$prepare->execute();
$results = $prepare->fetchAll(\PDO::FETCH_ASSOC);
$output = [];
if ($results) {
foreach ($results as $result) {
$output[$result['configKey']] = $result['configValue'];
}
}
$this->ctx->Wpf_Logger->writeSqlLog($tag, $sql, "", $startTime);
return $output;
} catch (Exception $ex) {
$this->ctx->Wpf_Logger->error($tag, "error_msg ==" . $ex->getMessage());
return [];
}
}
}