table = $table; $this->id = $id; $this->column = $column; $this->type = $type; $this->required = $required; $this->default = $default; } public function __toString(): string { // Return the value of the field in the database table return $this->value(); } /** * Get the value of the field in the database table * @return mixed The value of the field in the database table */ public function value(): mixed { // Get the value of the field in the database table global $db; $sql = "SELECT $this->column FROM $this->table WHERE id = $this->id"; $result = $db->query($sql); $row = $db->fetch_assoc($result); return $row[$this->column]; } /** * Set the value of the field in the database table * @param mixed $value The value of the field in the database table */ public function set(mixed $value): void { // Set the value of the field in the database table global /** @var db $db */ $db; // If the value is null, set it to null if ($value === null) { $sql = "UPDATE $this->table SET $this->column = NULL WHERE id = $this->id"; } // If the value is an integer, set it to the integer value elseif (is_int($value)) { $sql = "UPDATE $this->table SET $this->column = $value WHERE id = $this->id"; } // If the value is a string, escape it else { $value = $db->escape_string($value); $sql = "UPDATE $this->table SET $this->column = '$value' WHERE id = $this->id"; } $db->query($sql); } /** * Nullify the value of the field in the database table */ public function nullify(): void { // Set the value of the field in the database table to null global /** @var db $db */ $db; $sql = "UPDATE $this->table SET $this->column = NULL WHERE id = $this->id"; $db->query($sql); } }