mirror of
https://gitlab.com/hashborgir/d2tools.git
synced 2025-09-19 01:52:09 +00:00
DB Dump Working
This commit is contained in:
74
src/D2Database.php
Normal file
74
src/D2Database.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
GPLv2 (C) <2021> <HashCasper>
|
||||
|
||||
This file is part of D2IM.
|
||||
|
||||
D2IM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
D2IM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with D2IM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
class D2Database {
|
||||
|
||||
public function __construct() {
|
||||
PDO_Connect("sqlite:" . DB_FILE);
|
||||
}
|
||||
|
||||
public function createTables($file, $data) {
|
||||
$tableName = basename($file);
|
||||
$tableName = strtolower(substr($tableName, 0, -4));
|
||||
$sql = "CREATE TABLE IF NOT EXISTS `$tableName` (";
|
||||
foreach ($data[0] as $k => $v) {
|
||||
if (is_numeric($v)) {
|
||||
$dataType = "INT";
|
||||
} else {
|
||||
$dataType = "VARCHAR(255)";
|
||||
}
|
||||
$sql .= "`$k` $dataType NOT NULL,";
|
||||
}
|
||||
$sql = rtrim($sql, ",");
|
||||
$sql .= ")";
|
||||
$res = PDO_Execute($sql);
|
||||
}
|
||||
|
||||
public function fillsTables($file, $data) {
|
||||
$tableName = basename($file);
|
||||
$tableName = strtolower(substr($tableName, 0, -4));
|
||||
|
||||
foreach ($data as $d) {
|
||||
$sql = "INSERT INTO `$tableName` (";
|
||||
if (!empty($d)) {
|
||||
foreach ($d as $k => $v) {
|
||||
$sql .= "`$k`" . ",";
|
||||
}
|
||||
}
|
||||
$sql = rtrim($sql, ",");
|
||||
$sql .= ") ";
|
||||
|
||||
$sql .= "VALUES (";
|
||||
|
||||
if (!empty($d)) {
|
||||
foreach ($d as $k => $v) {
|
||||
$sql .= '"' . $v . '"' . ",";
|
||||
}
|
||||
}
|
||||
$sql = rtrim($sql, ",");
|
||||
$sql .= ");";
|
||||
|
||||
var_dump($sql);
|
||||
PDO_Execute($sql);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user