|
|
@@ -51,6 +51,13 @@ class db {
|
|
|
return mysqli_real_escape_string(db::$DB, $value);
|
|
|
}
|
|
|
|
|
|
+ public static function escape_nvp(array $nvp): array {
|
|
|
+ foreach($nvp as $name => $value) {
|
|
|
+ $nvp[$name] = db::escape($value);
|
|
|
+ }
|
|
|
+ return $nvp;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @return string
|
|
|
*/
|
|
|
@@ -95,19 +102,19 @@ class db {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param array $pairs
|
|
|
+ * @param array $nvp
|
|
|
* @param bool $escape
|
|
|
* @return string
|
|
|
*/
|
|
|
- public static function get_value_string(array $pairs, bool $escape = false): string {
|
|
|
+ public static function get_value_string(array $nvp, bool $escape = false): string {
|
|
|
|
|
|
if($escape) {
|
|
|
- $pairs = array_map(array("db", "escape"), $pairs);
|
|
|
+ $nvp = db::escape_nvp($nvp);
|
|
|
}
|
|
|
|
|
|
$string_array = [];
|
|
|
|
|
|
- foreach($pairs as $field => $value) {
|
|
|
+ foreach($nvp as $field => $value) {
|
|
|
if(is_null($value)) {
|
|
|
$string_array[] = "`$field`=NULL";
|
|
|
}
|
|
|
@@ -122,11 +129,11 @@ class db {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param array $pairs
|
|
|
+ * @param array $nvp
|
|
|
* @param array|bool $options
|
|
|
* @return string
|
|
|
*/
|
|
|
- public static function get_where_string(array $pairs, $options = []): string {
|
|
|
+ public static function get_where_string(array $nvp, $options = []): string {
|
|
|
|
|
|
$escape = false;
|
|
|
$fuzzy = false;
|
|
|
@@ -140,15 +147,14 @@ class db {
|
|
|
$fuzzy = $options["fuzzy"] ?? false;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
if($escape) {
|
|
|
- $pairs = array_map(array("db", "escape"), $pairs);
|
|
|
+ $nvp = db::escape_nvp($nvp);
|
|
|
}
|
|
|
|
|
|
$string_array = [];
|
|
|
|
|
|
- foreach($pairs as $field => $value) {
|
|
|
- if(is_null($value)) {
|
|
|
+ foreach($nvp as $field => $value) {
|
|
|
+ if($value === null) {
|
|
|
$string_array[] = "`$field` IS NULL";
|
|
|
}
|
|
|
else if(is_array($value)) {
|