@@ -12,6 +12,7 @@ $user = new User; | |||||
$user -> name = $_GET['name']; | $user -> name = $_GET['name']; | ||||
$user -> pass = implode ( | $user -> pass = implode ( | ||||
array_map (fn () => $chars[rand (0, strlen ($chars) - 1)], range (1, 8))); | array_map (fn () => $chars[rand (0, strlen ($chars) - 1)], range (1, 8))); | ||||
$user -> inheritance_code = implode (array_map (fn () => rand (0, 9), range (1, 12))); | |||||
echo [$user -> insert () -> id]; | echo [$user -> insert () -> id]; | ||||
@@ -0,0 +1,2 @@ | |||||
ALTER TABLE `users` ADD `inheritance_code` VARCHAR(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '引継ぎコード' AFTER `pass`, ADD `created_at` DATETIME NOT NULL AFTER `inheritance_code`, ADD `modified_at` DATETIME on update CURRENT_TIMESTAMP NOT NULL AFTER `created_at`, ADD `deleted_at` DATETIME NULL DEFAULT NULL AFTER `modified_at`; | |||||
@@ -6,6 +6,7 @@ User | |||||
var $id; | var $id; | ||||
var $name; | var $name; | ||||
var $pass; | var $pass; | ||||
var $inheritance_code; | |||||
public static function | public static function | ||||
find ( | find ( | ||||
@@ -28,6 +29,7 @@ User | |||||
$self -> id = $id; | $self -> id = $id; | ||||
$self -> name = $row['name']; | $self -> name = $row['name']; | ||||
$self -> pass = $row['pass']; | $self -> pass = $row['pass']; | ||||
$self -> inheritance_code = $row['inheritance_code']; | |||||
return $self; | return $self; | ||||
} | } | ||||
@@ -38,8 +40,16 @@ User | |||||
{ | { | ||||
$sql = " | $sql = " | ||||
INSERT INTO | INSERT INTO | ||||
users (name, pass) | |||||
VALUES ('{$this -> name}', '{$this -> pass}')"; | |||||
users ( | |||||
name, | |||||
pass, | |||||
inheritance_code, | |||||
created_at) | |||||
VALUES | |||||
('{$this -> name}', | |||||
'{$this -> pass}', | |||||
'{$this -> inheritance_code}', | |||||
NOW())"; | |||||
$GLOBALS['__db_connection'] -> query ($sql) | $GLOBALS['__db_connection'] -> query ($sql) | ||||
or die ("db_insert error $sql"); | or die ("db_insert error $sql"); | ||||