Skip to content

Commit 17bf74d

Browse files
authored
Merge pull request #4 from PhantPHP/Fix
Fix
2 parents b020edf + b5e79b5 commit 17bf74d

File tree

1 file changed

+9
-40
lines changed

1 file changed

+9
-40
lines changed

component/Service/MySQL.php

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,15 @@ public function execute(
3232
array $values = []
3333
): void {
3434
$statement = $this->getPdo()->prepare($query);
35-
$this->bindParams($statement, $values);
36-
$statement->execute();
35+
$statement->execute($values);
3736
}
3837

3938
public function getList(
4039
string $query,
4140
array $values = []
4241
): array {
4342
$statement = $this->getPdo()->prepare($query);
44-
$this->bindParams($statement, $values);
45-
$statement->execute();
43+
$statement->execute($values);
4644
$all = $statement->fetchAll();
4745

4846
if ($statement->rowCount() == 0) {
@@ -70,8 +68,7 @@ public function get(
7068
array $values = []
7169
): array {
7270
$statement = $this->getPdo()->prepare($query);
73-
$this->bindParams($statement, $values);
74-
$statement->execute();
71+
$statement->execute($values);
7572
$one = $statement->fetch();
7673

7774
if ($statement->rowCount() == 0) {
@@ -99,8 +96,7 @@ public function exist(
9996
array $values = []
10097
): bool {
10198
$statement = $this->getPdo()->prepare($query);
102-
$this->bindParams($statement, $values);
103-
$statement->execute();
99+
$statement->execute($values);
104100
$exist = $statement->fetch(PDO::FETCH_ASSOC);
105101

106102
return ($exist != false);
@@ -119,40 +115,13 @@ public function existByColumnValue(
119115
);
120116
}
121117

122-
private function bindParams(
123-
&$statement,
124-
array $values
125-
): void {
126-
foreach ($values as $param => $value) {
127-
if (is_object($value)) {
128-
$value = (string) $value;
129-
}
130-
$statement->bindParam($param, $value, $this->getParamType($value));
131-
}
132-
}
133-
134-
private function getParamType(
135-
mixed $value
136-
): int {
137-
if (is_int($value)) {
138-
return PDO::PARAM_INT;
139-
}
140-
if (is_float($value)) {
141-
return PDO::PARAM_INT;
142-
}
143-
if (is_bool($value)) {
144-
return PDO::PARAM_BOOL;
145-
}
146-
if (is_null($value)) {
147-
return PDO::PARAM_NULL;
148-
}
149-
150-
return PDO::PARAM_STR;
151-
}
152-
153118
protected function getPdo(
154119
): PDO {
155-
$this->pdo ??= new PDO(
120+
if ($this->pdo) {
121+
return $this->pdo;
122+
}
123+
124+
$this->pdo = new PDO(
156125
'mysql:host=' . $this->host . ';dbname=' . $this->dbname . ';port=' . $this->port . ';charset=' . $this->charset,
157126
$this->user,
158127
$this->pass,

0 commit comments

Comments
 (0)