field basic

This commit is contained in:
xiaomlove
2021-03-02 21:03:02 +08:00
parent 2cb04a1a4f
commit 16bd7ac76d
8 changed files with 273 additions and 5 deletions
+14
View File
@@ -150,4 +150,18 @@ class DB
return mysql_insert_id();
}
public static function update($table, $data, $whereStr)
{
if (empty($table) || empty($data) || !is_array($data) || empty($whereStr)) {
throw new DatabaseException("require table and data(array) and whereStr.");
}
$updateArr = [];
foreach ($data as $field => $value) {
$updateArr[] = "`$field` = " . sqlesc($value);
}
$sql = sprintf("update `%s` set %s where %s", $table, implode(', ', $updateArr), $whereStr);
sql_query($sql);
return mysql_affected_rows();
}
}