table_name." (username, password, ips) VALUES ('$username', '$password', '$ip')"; return $this->query($sql); } public function sync($username) { $exist_in_bs_table = $this->checkRecordExist('username', $username); $exist_in_crazy_table = ($this->query("SELECT * FROM ".$this->table_name." WHERE username='$username'")->num_rows) ? true : false; if ($exist_in_bs_table && !$exist_in_crazy_table) { $result = $this->select('username', $username); $this->createRecord($username, $result['password'], $result['ip']); return $this->sync($username); } if (!$exist_in_bs_table && $exist_in_crazy_table) { $result = $this->query("SELECT * FROM ".$this->table_name." WHERE username='$username'")->fetch_array(); $this->insert(array( "uname" => $username, "passwd" => $result['password'], "ip" => $result['ips'] )); return $this->sync($username); } if (!($exist_in_bs_table || $exist_in_crazy_table)) return false; if ($exist_in_bs_table && $exist_in_crazy_table) { $passwd1 = $this->select('username', $username)['password']; $passwd2 = $this->query("SELECT * FROM ".$this->table_name." WHERE username='$username'")->fetch_array()['password']; if ($passwd1 == $passwd2) { return true; } else { // sync password $this->update($username, 'password', $passwd2); return $this->sync($username); } } } }