From 1f261fe4fedef1eb979198990d9a51936922a2a3 Mon Sep 17 00:00:00 2001 From: "maxime.batista" Date: Mon, 6 Nov 2023 10:50:51 +0100 Subject: [PATCH] avoid use of 'RETURNING' sql clause --- .gitignore | 1 + public/utils.php | 8 ++++++-- src/Gateway/TacticInfoGateway.php | 7 ++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 05806f7..9124809 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .vs .idea .code +.vite vendor diff --git a/public/utils.php b/public/utils.php index ca9aa14..a3566fe 100644 --- a/public/utils.php +++ b/public/utils.php @@ -7,10 +7,14 @@ function get_public_path() { // find the server path of the index.php file $basePath = substr(__DIR__, strlen($_SERVER['DOCUMENT_ROOT'])); - $c = $basePath[strlen($basePath) - 1]; + $basePathLen = strlen($basePath); + if ($basePathLen == 0) + return ""; + + $c = $basePath[$basePathLen - 1]; if ($c == "/" || $c == "\\") { - $basePath = substr($basePath, 0, strlen($basePath) - 1); + $basePath = substr($basePath, 0, $basePathLen - 1); } return $basePath; } \ No newline at end of file diff --git a/src/Gateway/TacticInfoGateway.php b/src/Gateway/TacticInfoGateway.php index 9cc39db..1c9a190 100644 --- a/src/Gateway/TacticInfoGateway.php +++ b/src/Gateway/TacticInfoGateway.php @@ -26,10 +26,11 @@ class TacticInfoGateway { } public function insert(string $name): TacticInfo { - $row = $this->con->fetch( - "INSERT INTO TacticInfo(name, creation_date) VALUES(:name, CURRENT_TIMESTAMP) RETURNING id, creation_date", + $this->con->exec( + "INSERT INTO TacticInfo(name, creation_date) VALUES(:name, CURRENT_TIMESTAMP)", [":name" => [$name, PDO::PARAM_STR]] - )[0]; + ); + $row = $this->con->fetch("SELECT id, creation_date FROM TacticInfo ORDER BY id DESC LIMIT 1", [])[0]; return new TacticInfo(intval($row["id"]), $name, strtotime($row["creation_date"])); }