Bugfixing

This commit is contained in:
color.diff=auto 2021-03-26 15:44:33 -06:00
parent 358666c292
commit 1fd9f2165a
2 changed files with 34 additions and 28 deletions

View File

@ -17,6 +17,7 @@ if (file_exists("d2im.db")) {
$db->fillsTables($k, $v); $db->fillsTables($k, $v);
} }
} }
die();
// put in html redirect as backup, because // put in html redirect as backup, because
// for some odd reason windows gives // for some odd reason windows gives
// an error on header() but linux does not. // an error on header() but linux does not.

View File

@ -29,49 +29,54 @@ class D2Database {
$tableName = basename($file); $tableName = basename($file);
$tableName = strtolower(substr($tableName, 0, -4)); $tableName = strtolower(substr($tableName, 0, -4));
$sql = "CREATE TABLE IF NOT EXISTS `$tableName` ("; $sql = "CREATE TABLE IF NOT EXISTS `$tableName` (";
foreach ($data[0] as $k => $v) { if (!empty($data)) {
if (is_numeric($v)) { foreach ($data[0] as $k => $v) {
$dataType = "INT"; if (is_numeric($v)) {
} else { $dataType = "INT";
$dataType = "VARCHAR(255)"; } else {
$dataType = "VARCHAR(255)";
}
$sql .= "`$k` $dataType NOT NULL,";
} }
$sql .= "`$k` $dataType NOT NULL,";
} }
$sql = rtrim($sql, ","); $sql = rtrim($sql, ",");
$sql .= ")"; $sql .= ")";
$res = PDO_Execute($sql); $res = PDO_Execute($sql);
} }
public function fillsTables($file, $data) { public function fillsTables($file, $data) {
$tableName = basename($file); $tableName = basename($file);
$tableName = strtolower(substr($tableName, 0, -4)); $tableName = strtolower(substr($tableName, 0, -4));
$sql = ''; $sql = '';
foreach ($data as $d) { if (!empty($data)) {
$sql = "INSERT INTO `$tableName` ("; foreach ($data as $d) {
if (!empty($d)) { $sql = "INSERT INTO `$tableName` (";
foreach ($d as $k => $v) { if (!empty($d)) {
$sql .= "`$k`" . ","; foreach ($d as $k => $v) {
$sql .= "`$k`" . ",";
}
} }
$sql = rtrim($sql, ",");
$sql .= ") ";
} }
$sql = rtrim($sql, ",");
$sql .= ") ";
} }
$sql .= "VALUES "; $sql .= "VALUES ";
if (!empty($data)) {
foreach ($data as $d) { foreach ($data as $d) {
$sql .= "("; $sql .= "(";
if (!empty($d)) { if (!empty($d)) {
foreach ($d as $k => $v) { foreach ($d as $k => $v) {
$sql .= '"' . $v . '"' . ","; $sql .= '"' . $v . '"' . ",";
}
} }
$sql = rtrim($sql, ",");
$sql .= "), ";
} }
$sql = rtrim($sql, ","); $sql = rtrim($sql, ", ");
$sql .= "), "; PDO_Execute($sql);
} }
$sql = rtrim($sql, ", "); }
PDO_Execute($sql);
} }
}