Skip to content

Commit 97ce39c

Browse files
author
Karel Wintersky
committed
1.0.0
- PHP8 compatible code - removed apostrophes
1 parent fae7d8e commit 97ce39c

File tree

4 files changed

+30
-22
lines changed

4 files changed

+30
-22
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"require": {
1818
"php": ">=7.4 | 8.*",
1919
"ext-pdo": "*",
20-
"psr/log": "1.1.4"
20+
"psr/log": "^1 | ^2 | ^3"
2121
},
2222
"require-dev": {
2323
"predis/predis": "^2.0",

sources/Database/DBHelper.php

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ public static function makeInsertQuery(string $table, &$dataset, bool $pretty =
2727

2828
foreach ($dataset as $index => $value) {
2929
if (\strtoupper(\trim($value)) === 'NOW()') {
30-
$insert_fields[] = "{$pretty} `{$index}` = NOW()";
30+
$insert_fields[] = "{$pretty} {$index} = NOW()";
3131
unset($dataset[ $index ]);
3232
continue;
3333
}
3434

3535
if (\strtoupper(\trim($value)) === 'UUID()') {
36-
$insert_fields[] = "\r\n {$index} = UUID()";
36+
$insert_fields[] = "{$pretty} {$index} = UUID()";
3737
unset($dataset[$index]);
3838
continue;
3939
}
4040

41-
$insert_fields[] = "{$pretty} `{$index}` = :{$index}";
41+
$insert_fields[] = "{$pretty} {$index} = :{$index}";
4242
}
4343

4444
$query .= \implode(', ', $insert_fields) . ' ;';
@@ -64,11 +64,11 @@ public static function makeUpdateQuery(string $table, &$dataset, $where_conditio
6464
$set = [];
6565
$pretty = $pretty ? "\r\n" : '';
6666

67-
$query = "UPDATE `{$table}` SET";
67+
$query = "UPDATE {$table} SET";
6868

6969
foreach ($dataset as $index => $value) {
7070
if (\strtoupper(\trim($value)) === 'NOW()') {
71-
$set[] = "{$pretty} `{$index}` = NOW()";
71+
$set[] = "{$pretty} {$index} = NOW()";
7272
unset($dataset[ $index ]);
7373
continue;
7474
}
@@ -79,7 +79,7 @@ public static function makeUpdateQuery(string $table, &$dataset, $where_conditio
7979
continue;
8080
}
8181

82-
$set[] = "{$pretty} `{$index}` = :{$index}";
82+
$set[] = "{$pretty} {$index} = :{$index}";
8383
}
8484

8585
$query .= \implode(', ', $set);
@@ -117,11 +117,11 @@ public static function makeReplaceQuery(string $table, array &$dataset, string $
117117

118118
$pretty = $pretty ? "\r\n" : '';
119119

120-
$query = "REPLACE `{$table}` SET ";
120+
$query = "REPLACE {$table} SET ";
121121

122122
foreach ($dataset as $index => $value) {
123123
if (\strtoupper(\trim($value)) === 'NOW()') {
124-
$fields[] = "`{$index}` = NOW()";
124+
$fields[] = "{$index} = NOW()";
125125
unset($dataset[ $index ]);
126126
continue;
127127
}
@@ -132,7 +132,7 @@ public static function makeReplaceQuery(string $table, array &$dataset, string $
132132
continue;
133133
}
134134

135-
$fields[] = " `{$index}` = :{$index} ";
135+
$fields[] = " {$index} = :{$index} ";
136136
}
137137

138138
$query .= \implode(', ', $fields);
@@ -147,16 +147,19 @@ public static function makeReplaceQuery(string $table, array &$dataset, string $
147147
*
148148
* @param string $table
149149
* @param array $dataset
150+
* @param bool $pretty
150151
* @return string
151152
*/
152-
public static function buildReplaceQuery(string $table, array $dataset):string
153+
public static function buildReplaceQuery(string $table, array $dataset, bool $pretty = true):string
153154
{
155+
$pretty = $pretty ? "\r\n" : '';
156+
154157
$dataset_keys = \array_keys($dataset);
155158

156-
$query = "REPLACE INTO `{$table}` (";
159+
$query = "REPLACE INTO {$table} (";
157160

158161
$query.= \implode(', ', \array_map(function ($i){
159-
return "`{$i}`";
162+
return "{$i}";
160163
}, $dataset_keys));
161164

162165
$query.= " ) VALUES ( ";
@@ -174,14 +177,17 @@ public static function buildReplaceQuery(string $table, array $dataset):string
174177
* @param string $table
175178
* @param array $dataset
176179
* @param null $where_condition - строка условия без WHERE ('x=0 AND y=0' ) или массив условий ['x=0', 'y=0']
180+
* @param bool $pretty
177181
* @return string
178182
*/
179-
public static function buildUpdateQuery(string $table, array $dataset = [], $where_condition = null):string
183+
public static function buildUpdateQuery(string $table, array $dataset = [], $where_condition = null, bool $pretty = true):string
180184
{
181-
$query = "UPDATE `{$table}` SET ";
185+
$pretty = $pretty ? "\r\n" : '';
186+
187+
$query = "UPDATE {$table} SET ";
182188

183-
$query.= \implode(', ', \array_map(function ($key, $value){
184-
return "\r\n`{$key}` = :{$key}";
189+
$query.= \implode(', ', \array_map(function ($key, $value) use ($pretty){
190+
return "{$pretty} {$key} = :{$key}";
185191
}, \array_keys($dataset), $dataset));
186192

187193
$where
@@ -209,12 +215,12 @@ public static function buildUpdateQuery(string $table, array $dataset = [], $whe
209215
*/
210216
public static function buildReplaceQueryMVA(string $table, array $dataset, array $mva_attributes):array
211217
{
212-
$query = "REPLACE INTO `{$table}` (";
218+
$query = "REPLACE INTO {$table} (";
213219

214220
$dataset_keys = \array_keys($dataset);
215221

216222
$query .= \implode(', ', \array_map( static function ($i){
217-
return "`{$i}`";
223+
return "{$i}";
218224
}, $dataset_keys));
219225

220226
$query .= " ) VALUES ( ";

sources/Database/DBMultiConnector.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public function __construct($suffix = null)
4141
$state_error_code = 0;
4242
$state_error_msg = '';
4343

44+
$db_driver = $db_host = $db_name = $db_user = $db_pass = $db_port = null;
45+
4446
try {
4547
if (\is_null($config)) {
4648
throw new RuntimeException("Arris\DBMultiConnector class can't find configuration data for suffix {$suffix}" . PHP_EOL, 2);
@@ -53,6 +55,7 @@ public function __construct($suffix = null)
5355
$db_pass = $config['password'] ?? '';
5456
$db_port = $config['port'] ?? 3306;
5557

58+
5659
switch ($db_driver) {
5760
case 'mysql': {
5861
$dsl = \sprintf("mysql:host=%s;port=%s;dbname=%s",
@@ -85,9 +88,9 @@ public function __construct($suffix = null)
8588
}
8689
} // switch
8790

88-
if (isset($config['charset']) && !\is_null($config['charset'])) {
91+
if (isset($config['charset']) && !empty($config['charset'])) {
8992
$sql = "SET NAMES {$config['charset']}";
90-
if (isset($config['charset_collate']) && !\is_null($config['charset_collate'])) {
93+
if (isset($config['charset_collate']) && !empty($config['charset_collate'])) {
9194
$sql .= " COLLATE {$config['charset_collate']}";
9295
}
9396
$dbh->exec($sql);

sources/Database/DBWrapper.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use PDO;
66
use Psr\Log\LoggerInterface;
77
use Psr\Log\NullLogger;
8-
use stdClass;
98

109
/**
1110
* @method int|false exec(string $statement = '')

0 commit comments

Comments
 (0)