mirror of
https://codeberg.org/vlw/php-mysql.git
synced 2025-09-14 00:33:41 +02:00
feat: add static col and val constructors (#3)
This commit is contained in:
parent
bbfb31707a
commit
aa73cf987d
1 changed files with 21 additions and 0 deletions
|
@ -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
|
// Get result as an associative array
|
||||||
public function return_array(string $sql, mixed $params = null): array {
|
public function return_array(string $sql, mixed $params = null): array {
|
||||||
$query = $this->run_query($sql, $params);
|
$query = $this->run_query($sql, $params);
|
||||||
|
|
Loading…
Add table
Reference in a new issue