我以前从来没有这样做过。我不是专业人员,但我大致知道MySQL是如何工作的。我对PHP略知一二,但仍处于初学者阶段。我目前也有一个方法在脑海中去它。
然而,在我浪费2个多小时学习我做错了什么之前,我想我应该先问一下你们是怎么做的。我从一个(相对)小的数组开始,当我理解得很好时,我就开始做大的事情。
数组:http://pastebin.com/g8RyxtP5
. .如何将其导入MySQL?现在我最初的想法是制作表格,它现在看起来像这样:
<?php
include "login.php";
include "createdb.php";
$con = mysqli_connect($mysql_host, $mysql_user, $mysql_pass, $mysql_table)
or die("Some error occurred during connection " . mysqli_error($con));
/*$sql = "CREATE TABLE Career (
ID int NOT NULL AUTO_INCREMENT PRIMARY KEY,
Username varchar(32),
Password varchar(32),
Battletag varchar(32),
Region varchar(2)
)
";*/
$sql = "CREATE TABLE career (
ID int NOT NULL AUTO_INCREMENT PRIMARY KEY,
battletag varchar(32),
lastHeroPlayed varchar(32),
lastUpdated varchar(32),
monsters varchar(32),
elites varchar(32),
hardcoreMonsters varchar(32),
barbarian varchar(32),
crusader varchar(32),
demon-hunter varchar(32),
monk varchar(32),
witch-doctor varchar(32),
wizard varchar(32),
paragonLevel varchar(32),
paragonLevelHardcore varchar(32),
h1name varchar(32),
h1id varchar(32),
h1level varchar(32),
h1hardcore varchar(32),
h1gender varchar(32),
h1dead varchar(32),
h1class varchar(32),
h1last-updated varchar(32),
h2name varchar(32),
h2id varchar(32),
h2level varchar(32),
h2hardcore varchar(32),
h2gender varchar(32),
h2dead varchar(32),
h2class varchar(32),
h2last-updated varchar(32),
h3name varchar(32),
h3id varchar(32),
h3level varchar(32),
h3hardcore varchar(32),
h3gender varchar(32),
h3dead varchar(32),
h3class varchar(32),
h3last-updated varchar(32),
h4name varchar(32),
h4id varchar(32),
h4level varchar(32),
h4hardcore varchar(32),
h4gender varchar(32),
h4dead varchar(32),
h4class varchar(32),
h4last-updated varchar(32),
h5name varchar(32),
h5id varchar(32),
h5level varchar(32),
h5hardcore varchar(32),
h5gender varchar(32),
h5dead varchar(32),
h5class varchar(32),
h5last-updated varchar(32),
h6name varchar(32),
h6id varchar(32),
h6level varchar(32),
h6hardcore varchar(32),
h6gender varchar(32),
h6dead varchar(32),
h6class varchar(32),
h6last-updated varchar(32),
h7name varchar(32),
h7id varchar(32),
h7level varchar(32),
h7hardcore varchar(32),
h7gender varchar(32),
h7dead varchar(32),
h7class varchar(32),
h7last-updated varchar(32),
h8name varchar(32),
h8id varchar(32),
h8level varchar(32),
h8hardcore varchar(32),
h8gender varchar(32),
h8dead varchar(32),
h8class varchar(32),
h8last-updated varchar(32),
h9name varchar(32),
h9id varchar(32),
h9level varchar(32),
h9hardcore varchar(32),
h9gender varchar(32),
h9dead varchar(32),
h9class varchar(32),
h9last-updated varchar(32),
h10name varchar(32),
h10id varchar(32),
h10level varchar(32),
h10hardcore varchar(32),
h10gender varchar(32),
h10dead varchar(32),
h10class varchar(32),
h10last-updated varchar(32),
h11name varchar(32),
h11id varchar(32),
h11level varchar(32),
h11hardcore varchar(32),
h11gender varchar(32),
h11dead varchar(32),
h11class varchar(32),
h11last-updated varchar(32),
h12name varchar(32),
h12id varchar(32),
h12level varchar(32),
h12hardcore varchar(32),
h12gender varchar(32),
h12dead varchar(32),
h12class varchar(32),
h12last-updated varchar(32),
";
if (mysqli_query($con,$sql)) {
echo "TABLE 'Career' created successfully!<br>";
} else {
echo "Error creating table: " . mysqli_error($con)."<br>";
}
mysqli_query($con, $sql);
表创建后,我要做一些PHP/MySQL魔术(基本上是学习我去)得到数组->parse->push到MySQL ?
谢谢你的建议。我不应该做什么/我应该怎么做?
编辑:好吧,我想也许我可以做一个表,并包括定义职业变量"战斗标签"到每个英雄单独(以及任何重要的信息,我需要每个英雄)。我觉得这比我的好。
$sql = "CREATE TABLE heros (
ID int NOT NULL AUTO_INCREMENT PRIMARY KEY,
battletag varchar(64) ,
name varchar(32),
id int,
level int,
hardcore bool,
gender bool,
dead bool,
class varchar(32),
last-updated TIMESTAMP
";
$sql2 = "CREATE TABLE career (
ID int NOT NULL AUTO_INCREMENT PRIMARY KEY,
battletag varchar(64),
lastHeroPlayed varchar(32),
lastUpdated TIMESTAMP,
monsters int,
elites int,
hardcoreMonsters int,
barbarian DOUBLE(4,3),
crusader DOUBLE(4,3),
demon-hunter DOUBLE(4,3),
monk DOUBLE(4,3),
witch-doctor DOUBLE(4,3),
wizard DOUBLE(4,3),
paragonLevel int,
paragonLevelHardcore int
";
从1到12…
h12name varchar(32),
h12id varchar(32),
h12level varchar(32),
h12hardcore varchar(32),
h12gender varchar(32),
h12dead varchar(32),
h12class varchar(32),
h12last-updated varchar(32),
下面可以是1列"GAME_NAME"所以你仍然可以添加....
$sql = "CREATE TABLE career (
ID int NOT NULL AUTO_INCREMENT PRIMARY KEY,
battletag varchar(32),
lastHeroPlayed varchar(32),
lastUpdated varchar(32),
monsters varchar(32),
elites varchar(32),
hardcoreMonsters varchar(32),
barbarian varchar(32),
crusader varchar(32),
demon-hunter varchar(32),
monk varchar(32),
witch-doctor varchar(32),
wizard varchar(32),
paragonLevel varchar(32),
paragonLevelHardcore varchar(32),
我建议这样创建一个表…或者您可以创建2个连接表,一个用于game,一个用于hnn…
name_game varchar(150)
hname varchar(32),
hid varchar(32),
hlevel varchar(32),
hhardcore varchar(32),
hgender varchar(32),
hdead varchar(32),
hclass varchar(32),
hlast-updated varchar(32),
冗余只放在1个表..............