From 0cd619156462002b08de69bdb5361fd94fe77cb7 Mon Sep 17 00:00:00 2001 From: Emanuel Bitkov Date: Mon, 13 May 2024 15:52:30 +0200 Subject: [PATCH 1/2] reverted deletion of `Mini\Libs\Helper` and moved it to `Mini\Core\Helper` --- application/Core/Helper.php | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 application/Core/Helper.php diff --git a/application/Core/Helper.php b/application/Core/Helper.php new file mode 100644 index 0000000..01eb396 --- /dev/null +++ b/application/Core/Helper.php @@ -0,0 +1,57 @@ + $value) { + + // check if named parameters (':param') or anonymous parameters ('?') are used + if (is_string($key)) { + $keys[] = '/' . $key . '/'; + } else { + $keys[] = '/[?]/'; + } + + // bring parameter into human-readable format + if (is_string($value)) { + $values[$key] = "'" . $value . "'"; + } elseif (is_array($value)) { + $values[$key] = implode(',', $value); + } elseif (is_null($value)) { + $values[$key] = 'NULL'; + } + } + + /* + echo "
[DEBUG] Keys:
";
+        print_r($keys);
+
+        echo "\n[DEBUG] Values: ";
+        print_r($values);
+        echo "
"; + */ + + $raw_sql = preg_replace($keys, $values, $raw_sql, 1, $count); + + return $raw_sql; + } + +} From 3cba5ceeee92139da641403cb4d922f7cfb85089 Mon Sep 17 00:00:00 2001 From: Emanuel Bitkov Date: Mon, 13 May 2024 15:53:17 +0200 Subject: [PATCH 2/2] add namespace to Helper --- application/Model/Song.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/Model/Song.php b/application/Model/Song.php index 1750116..9a49750 100644 --- a/application/Model/Song.php +++ b/application/Model/Song.php @@ -50,7 +50,7 @@ public function addSong($artist, $track, $link) $parameters = array(':artist' => $artist, ':track' => $track, ':link' => $link); // useful for debugging: you can see the SQL behind above construction by using: - // echo '[ PDO DEBUG ]: ' . Helper::debugPDO($sql, $parameters); exit(); + // echo '[ PDO DEBUG ]: ' . \Mini\Core\Helper::debugPDO($sql, $parameters); exit(); $query->execute($parameters); }