From 5936fd0993f54b959ec9693eb686f78b653306fe Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Tue, 30 May 2023 12:48:23 +0200 Subject: [PATCH] feat: add static col and val constructors --- src/MySQL.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/MySQL.php b/src/MySQL.php index a52e118..f6b6aea 100644 --- a/src/MySQL.php +++ b/src/MySQL.php @@ -67,6 +67,27 @@ /* ---- */ + // Create comma separated list (CSV) from array + private static function csv(array $values): string { + return implode(",", $values); + } + + // Create CSV from columns + public static function columns(array|string $columns): string { + return is_array($columns) + ? (__CLASS__)::csv($columns) + : $columns; + } + + // Return CSV of '?' for use with prepared statements + public static function values(array|string $values): string { + return is_array($values) + ? (__CLASS__)::csv(array_fill(0, count($values), "?")) + : "?"; + } + + /* ---- */ + // Get result as an associative array public function return_array(string $sql, mixed $params = null): array { $query = $this->run_query($sql, $params);