mirror of
https://codeberg.org/vlw/php-sqlite.git
synced 2025-09-14 04:43:42 +02:00
feat: add static col and val constructors
This commit is contained in:
parent
cc3a5493c1
commit
f7d60b9e25
1 changed files with 21 additions and 0 deletions
|
@ -59,6 +59,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 column indexed array
|
// Get result as column indexed array
|
||||||
public function return_array(string $query, mixed $values = []): array {
|
public function return_array(string $query, mixed $values = []): array {
|
||||||
$result = $this->run_query($query, $values);
|
$result = $this->run_query($query, $values);
|
||||||
|
|
Loading…
Add table
Reference in a new issue