diff --git a/src/MySQL.php b/src/MySQL.php index cf7e9ef..ba1baa0 100644 --- a/src/MySQL.php +++ b/src/MySQL.php @@ -8,8 +8,10 @@ use mysqli_stmt; use mysqli_result; + use libmysqldriver\Order; use libmysqldriver\Operators; + require_once "Order.php"; require_once "Operators.php"; // Interface for MySQL_Driver with abstractions for data manipulation @@ -52,7 +54,11 @@ // Convert all boolean type values to tinyints in array private static function filter_booleans(array $values): array { - return array_map(fn($v): mixed => gettype($v) === "boolean" ? self::filter_boolean($v) : $v, $values); + return array_map(fn(mixed $v): mixed => gettype($v) === "boolean" ? self::filter_boolean($v) : $v, $values); + } + + private static function array_wrap_accents(array $input): array { + return array_map(fn(mixed $v): string => "`{$v}`", $input); } // Return value(s) that exist in $this->model @@ -209,10 +215,11 @@ return $this; } - // Create CSV from columns - $sql = implode(",", array_keys($order_by)); - // Create pipe DSV from values - $sql .= " " . implode("|", array_values($order_by)); + $test = array_map(fn(Order|string $kw): Order => $kw instanceof Order ? $kw : Order::tryFrom($kw), array_values($order_by)); + + // Create CSV string with Prepared Statement abbreviations from length of fields array. + //$sql = array_map(fn(string $column, Order|string $kw): string => "`{$column}` " . Order::tryFrom($kw), array_keys($order_by), array_values($order_by)); + //$sql = implode(",", $sql); $this->order_by = $sql; return $this; @@ -236,7 +243,7 @@ } // Create CSV from columns or default to SQL NULL as a string - $columns_sql = $this->columns ? implode(",", $this->columns) : "NULL"; + $columns_sql = $this->columns ? implode(",", self::array_wrap_accents($this->columns)) : "NULL"; // Create LIMIT statement if argument is defined $limit_sql = !is_null($this->limit) ? " LIMIT {$this->limit}" : ""; @@ -268,7 +275,7 @@ } // Create CSV string with Prepared Statement abbreviations from length of fields array. - $changes = array_map(fn($column) => "{$column} = ?", array_keys($entity)); + $changes = array_map(fn($column) => "`{$column}` = ?", array_keys($entity)); $changes = implode(",", $changes); // Get array of SQL WHERE string and filter values diff --git a/src/Order.php b/src/Order.php new file mode 100644 index 0000000..5c7fddb --- /dev/null +++ b/src/Order.php @@ -0,0 +1,8 @@ +