Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Facebook、Google Play或Game Center id的MySQL高分表的主键?_Mysql_Database - Fatal编程技术网

使用Facebook、Google Play或Game Center id的MySQL高分表的主键?

使用Facebook、Google Play或Game Center id的MySQL高分表的主键?,mysql,database,Mysql,Database,我有一个高分表,目前使用facebook登录记录用户的高分 然而,我知道并不是每个人都想使用facebook来存储高分,事实上,很多人会立即被facebook登录所吓倒 所以我的想法是在android设备上使用他们的Google Play id,在iOs设备上使用他们的Game Center id 我的问题是,我希望用户能够在两个平台上统一他们的游戏。这是我计划在游戏中保持facebook登录的唯一原因,因为它的ID号不依赖于平台 例如。 用户在iPhone上玩游戏时,我检索他们的GC id,并

我有一个高分表,目前使用facebook登录记录用户的高分

然而,我知道并不是每个人都想使用facebook来存储高分,事实上,很多人会立即被facebook登录所吓倒

所以我的想法是在android设备上使用他们的Google Play id,在iOs设备上使用他们的Game Center id

我的问题是,我希望用户能够在两个平台上统一他们的游戏。这是我计划在游戏中保持facebook登录的唯一原因,因为它的ID号不依赖于平台

例如。 用户在iPhone上玩游戏时,我检索他们的GC id,并使用该id填充mysql表中的“profile_id”主键。 然后他们使用facebook登录。最好创建一个新的行,将facebook ID作为“profile\u ID”,然后将以前的profile\u ID放入“apple\u ID”列中? 这样,如果他们使用facebook登录Android手机,我就可以从他们的iOS会话中检索游戏数据

在我看来,这可能有一个相当简单的解决方案,但我陷入了一个循环中,你想用一种方法来做,然后意识到你以前已经尝试过了

有没有人对如何做到这一点有什么好的想法

编辑:我应该补充一点,我正在思考的一个问题就是这个。假设我为用户存储了一个facebook id和一个apple id。如果下次他们更新分数时没有登录facebook,因此只发送apple id作为查询的一部分,我如何确保我没有将facebook id字段替换为null或“”

我可以做到:

if ($facebookID != "" && $facebookID != NULL)
{
$sql = "UPDATE scores SET facebook_id = '$facebookID' WHERE profile_id = $profile_id;";

}

if ($appleID != "" && $appleID != NULL)
{
$sql = "UPDATE scores SET apple_id = '$appleID' WHERE profile_id = $profile_id;";

}

if ($googleID != "" && $googleID != NULL)
{
$sql = "UPDATE scores SET google_id = '$googleID' WHERE profile_id = $profile_id;";

}

但这似乎不是很有效。如果变量不为null/空白,是否有办法只更新字段?

唯一用户和登录凭据的概念应该分开。在表示唯一用户的用户表上,需要Guid、Int或BigInt主键。那么他们使用什么凭证就无关紧要了。如果需要添加的“登录”凭据的数量相当静态,则可以将它们作为列添加到同一个表中。如果您希望它是动态的,您需要另一个表,其中每一行都类似于UserId(fk到user table)、LoginType(1=facebook等)、Username、PasswordHash,然后通过添加新的LoginType,您可以相当容易地为新的身份验证提供者添加登录逻辑。然后,您可以通过单个表联接检索用户及其登录信息

再说一次,我不确定你到底需要什么,但我的解释是这样的

CREATE TABLE [dbo].[Users](
    [UserId] [bigint] IDENTITY(1,1) NOT NULL,
    [Username] [nvarchar](150) NOT NULL,
    [Enabled] bit NOT NULL)

    CREATE TABLE [dbo].[UserProfiles](
    [UserId] [bigint],  -- Combined Key (UserId, and ProfileServiceId)
    [ProfileServiceId] [nvarchar] (150),
    [ProfileType] [int] NOT NULL, -- 1 = Facebook, 2 = Google, etc..    
    [Enabled] bit NOT NULL)

    CREATE TABLE [dbo].[UserScores](
    [UserScoreId] [bigint] IDENTITY(1,1) NOT NULL,
    [UserId] [bigint],
    [ProfileServiceId] [nvarchar] (150),
    [ScoreValue] [int] NOT NULL

    -- Get all Facebook scores for current user
    select * from UserScores where UserId = $currentUser.UserId and ProfileServiceId = $currentUser.FacebookProfileId

    -- Get all scores for current user 
    select * from UserScores where UserId = $currentUser.UserId

    -- Get all profiles for current user
    select * from UserProfiles where UserId = $currentUser.UserId

    -- See if user has a facebook profile
    select * from UserProfiles where UserId = $currentUser.UserId and ProfileType = $ProfileTypes.Facebook

唯一用户和登录凭证的概念应该分开。在表示唯一用户的用户表上,需要Guid、Int或BigInt主键。那么他们使用什么凭证就无关紧要了。如果需要添加的“登录”凭据的数量相当静态,则可以将它们作为列添加到同一个表中。如果您希望它是动态的,您需要另一个表,其中每一行都类似于UserId(fk到user table)、LoginType(1=facebook等)、Username、PasswordHash,然后通过添加新的LoginType,您可以相当容易地为新的身份验证提供者添加登录逻辑。然后,您可以通过单个表联接检索用户及其登录信息

再说一次,我不确定你到底需要什么,但我的解释是这样的

CREATE TABLE [dbo].[Users](
    [UserId] [bigint] IDENTITY(1,1) NOT NULL,
    [Username] [nvarchar](150) NOT NULL,
    [Enabled] bit NOT NULL)

    CREATE TABLE [dbo].[UserProfiles](
    [UserId] [bigint],  -- Combined Key (UserId, and ProfileServiceId)
    [ProfileServiceId] [nvarchar] (150),
    [ProfileType] [int] NOT NULL, -- 1 = Facebook, 2 = Google, etc..    
    [Enabled] bit NOT NULL)

    CREATE TABLE [dbo].[UserScores](
    [UserScoreId] [bigint] IDENTITY(1,1) NOT NULL,
    [UserId] [bigint],
    [ProfileServiceId] [nvarchar] (150),
    [ScoreValue] [int] NOT NULL

    -- Get all Facebook scores for current user
    select * from UserScores where UserId = $currentUser.UserId and ProfileServiceId = $currentUser.FacebookProfileId

    -- Get all scores for current user 
    select * from UserScores where UserId = $currentUser.UserId

    -- Get all profiles for current user
    select * from UserProfiles where UserId = $currentUser.UserId

    -- See if user has a facebook profile
    select * from UserProfiles where UserId = $currentUser.UserId and ProfileType = $ProfileTypes.Facebook

你是说我可以通过使用自动增量创建一个唯一的用户。然后存储我从facebookid、appleid和googleid收到的任何值。然后,当他们下次登录时,只需检查我在查询中收到了哪些,并使用这些信息来确定下一步要做什么(即更新highscores设置点=$points,其中facebook=facebookid或apple=appleid或google=googleid)?嗯,我想这取决于你如何跟踪你的“分数”,但实际上,您应该针对用户唯一的UserId应用分数,而不管他的服务id是什么。更新highscores SET points=$points其中UserId=$currentUser->id然后当您需要获取分数时,您可以查看分数表,如果您需要高分用户的facebook id,可以从UserCredentials中选择*,其中UserId=$HighScoresUser和LoginType=1,假设LoginType 1是facebook的查找,或者如果你需要谷歌2个,如果你需要苹果3个,等等……那么你是说我可以举个例子:通过使用自动增量创建一个独特的用户。然后存储我从facebookid、appleid和googleid收到的任何值。然后,当他们下次登录时,只需检查我在查询中收到了哪些,并使用这些信息来确定下一步要做什么(即更新highscores设置点=$points,其中facebook=facebookid或apple=appleid或google=googleid)?嗯,我想这取决于你如何跟踪你的“分数”,但实际上,您应该针对用户唯一的UserId应用分数,而不管他的服务id是什么。更新highscores SET points=$points其中UserId=$currentUser->id然后当您需要获取分数时,您可以查看分数表,如果您需要高分用户的facebook id,可以从UserCredentials中选择*,其中UserId=$HighScoresUser和LoginType=1,假设LoginType 1是facebook的查找,或者如果你需要谷歌,2个,如果你需要苹果,3个等等。你要做的是使用所谓的“自然密钥”作为你的用户主键,但是你的“自然密钥”跨越不同的系统,必须在代码中进行不同的处理。这就是为什么它看起来如此粗糙和不可缩放。请考虑为用户使用标识字段,并将凭据与您的唯一标识符分开。这是很好的建议吗?我不相信。@草莓:你认为在任何地方都有3张硬编码支票会让你失望吗