2017-07-17 2 views
0

Ich erstelle eine Installationsseite, auf der der neue Benutzer seinen Datenbank-Host, Benutzernamen, Host und Passwort eingibt. Ich habe das getan und es funktioniert.PHP - mehrere Tabellen erstellen

Ich muss es machen, damit es eine Tabelle erstellt.

Ich weiß, wie es geht, aber nicht mit meinem ganzen SQL-Export.

Ich muss meinen gesamten SQL-Export in ihre Datenbank einfügen.

Ich bekomme einen Fehler in der Zeile mit online_users, aber ich bin mir nicht sicher warum.

My SQL-Export ist:

  $sql = " 
      CREATE TABLE IF NOT EXISTS failed (
      cpukey varchar(32) NOT NULL, 
      ip varchar(30) NOT NULL, 
      kvdata blob 
     ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 


      CREATE TABLE IF NOT EXISTS online_users (
      session char(100) NOT NULL DEFAULT '', 
      time int(11) NOT NULL DEFAULT '0', 
      username varchar(255) NOT NULL 
     ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 

      INSERT INTO online_users (session, time, username) VALUES 
      ('s9p65g909gg9l6qh7dtr947hp4', 1500315177, 'BenzaHdd'); 


      CREATE TABLE IF NOT EXISTS serversettings (
      freemode tinyint(1) NOT NULL DEFAULT '0', 
      bypasses tinyint(1) NOT NULL DEFAULT '1', 
      id int(255) NOT NULL, 
      port int(10) NOT NULL, 
      token varchar(255) NOT NULL, 
      listener_ip text NOT NULL, 
      LogLocation varchar(255) NOT NULL 
     ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 

      INSERT INTO serversettings (freemode, bypasses, id, port, token, listener_ip, LogLocation) VALUES 
      (1, 1, 1, 52, '675DFE06DC49999AE153815BD9A8818B', '192.168.0.1', 'C:\\Program Files (x86)\\Ampps\\www\\configuration\\log\\console.log'); 

      CREATE TABLE IF NOT EXISTS sitesettings (
      site_name varchar(50) NOT NULL DEFAULT 'TeamXerone', 
      team_motto varchar(100) NOT NULL DEFAULT 'The Art of Modding', 
      site_url varchar(999) NOT NULL DEFAULT 'http://localhost/XBL/', 
      id int(255) NOT NULL 
     ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1; 

      INSERT INTO sitesettings (site_name, team_motto, site_url, id) VALUES 
      ('ProjectBenza', 'Generation Infinite', 'http://localhost', 1); 

      CREATE TABLE IF NOT EXISTS tokens (
      id int(11) NOT NULL, 
      user_id varchar(999) NOT NULL, 
      token varchar(300) NOT NULL, 
      generate_by varchar(99) NOT NULL, 
      used int(1) NOT NULL DEFAULT '0', 
      used_by varchar(99) DEFAULT NULL, 
      time_generated datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, 
      durability int(11) NOT NULL COMMENT '0 = 1 day | 1 = 7 days | 2 = 14 days | 3 = 31 days | 4 = 3 months | 5 = 6 months | 6 = year | 7 = lifetime' 
     ) ENGINE=InnoDB AUTO_INCREMENT=90 DEFAULT CHARSET=latin1; 

      INSERT INTO tokens (id, user_id, token, generate_by, used, used_by, time_generated, durability) VALUES 
      (71, 'BenzaHdd', 'ABC-123-45X', 'BenzaHdd', 0, NULL, '2017-07-15 17:54:01', 99), 
      (83, 'BenzaHdd', '58PN-756MV0-0YFN', 'BenzaHdd', 0, NULL, '2017-07-15 19:49:32', 1), 
      (89, 'Client', 'LEJU-GAR008-EBOJ', 'BenzaHdd', 0, NULL, '2017-07-15 20:11:38', 99); 

      CREATE TABLE IF NOT EXISTS updates (
      id int(99) NOT NULL, 
      title varchar(99) DEFAULT NULL, 
      description varchar(999) DEFAULT NULL, 
      postedBy varchar(99) DEFAULT NULL, 
      timePosted datetime NOT NULL DEFAULT CURRENT_TIMESTAMP 
     ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1; 

      INSERT INTO updates (id, title, description, postedBy, timePosted) VALUES 
      (1, 'Launch of backend', 'This is the launch of my super advanced backend I have been working on for many, many months. I have finally decided to launch a stable and advanced version of this backend and will continue to add more and more as I think of new ideas. Prices will be shown in my skype mood.', 'Admin', '2016-12-14 21:05:54'); 

      CREATE TABLE IF NOT EXISTS users (
      id int(11) NOT NULL, 
      username varchar(50) NOT NULL DEFAULT 'User', 
      password varchar(255) DEFAULT 'Client', 
      email varchar(100) DEFAULT NULL, 
      cpukey varchar(32) DEFAULT NULL, 
      salt varchar(32) DEFAULT NULL, 
      ip varchar(32) NOT NULL DEFAULT '127.0.0.1', 
      time datetime DEFAULT NULL, 
      titleid text NOT NULL, 
      enabled tinyint(1) NOT NULL DEFAULT '0', 
      kvdata blob, 
      lastonline datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, 
      profile_picture varchar(999) NOT NULL DEFAULT 'images/default.jpg', 
      userLevel int(1) NOT NULL DEFAULT '0', 
      register_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, 
      customlifetimenotify varchar(40) DEFAULT 'XboxPal - Change your notify on our site', 
      gamertag varchar(16) NOT NULL DEFAULT 'None' 
     ) ENGINE=InnoDB AUTO_INCREMENT=88 DEFAULT CHARSET=latin1; 

      INSERT INTO users (id, username, password, email, cpukey, salt, ip, time, titleid, enabled, kvdata, lastonline, profile_picture, userLevel, register_time, customlifetimenotify, gamertag) VALUES 
      (71, 'BenzaHdd', '$2y$10$Of8OZoXuZOwYIN65Yr1vPOQlCigAByxXmqvDd.GZQvWppBlQckq5W', '[email protected]', 'D31E025FF263E0B8AED87052BA86E51D', NULL, '94.9.19.252', '2018-08-29 00:00:02', '', 1, NULL, '2017-07-09 18:24:11', '../uploads/635933476972091420917241652_bl.jpg', 3, '2017-04-06 12:53:28', 'Ben is a fucking boss', 'None'), 
      (72, 'Benny', '$2y$10$2ojCm39w45NAONn0.XqeLeHyElC/7yyRVCnvxjKVo1kAkPNQ3I6XG', '[email protected]', '99999999999999999999999999999999', NULL, '204.13.204.125', '2018-07-06 00:00:00', '', 1, NULL, '2017-07-08 19:27:57', '../uploads/myAvatar black back.png', 0, '2017-07-18 00:00:00', 'Ben is a fucking god.', 'None'), 
      (73, 'TomGydey', '$2y$10$qnPbhfH0RbXmRi8RZ1RNKedVdqiYTPdUsg4GDK/5vhhA.DI2lmer2', '[email protected]', '99999999999999999999999999999999', NULL, '79.67.114.16', '2018-07-01 00:00:00', '', 1, NULL, '2017-07-07 13:24:25', 'http://ya-techno.com/forum/images/icons/myIcons/red-xbox-256.png', 0, '2017-07-07 11:54:49', 'XboxPal - Change your notify on our site', 'None'), 
      (85, '', 'Client', '', '', NULL, '127.0.0.1', '0000-00-00 00:00:00', '', 0, NULL, '2017-07-17 18:37:11', 'images/default.jpg', 0, '2017-07-17 18:37:11', '', 'None'); 
     "; 

     if(mysqli_query($con, $sql)){ 
      echo "Table created successfully."; 
     } else{ 
      echo "ERROR: Could not able to execute $sql. " . mysqli_error($con); 
     } 
+1

Welchen Fehler bekommen Sie? – Adam

+0

@AdamA 'Sie haben einen Fehler in Ihrer SQL-Syntax; Überprüfen Sie das Handbuch, das Ihrer MySQL-Server-Version für die richtige Syntax in der Nähe von 'CREATE TABLE WENN NICHT EXISTS online_users (Sitzung char (100) NICHT' in Zeile 8 'entspricht – Benza

+0

So loggen Sie sich in jemandes Datenbank und führen Abfragen auf ihrer Datenbank Das klingt nach einer schrecklichen Sicherheitsvorkehrung und nicht zu vergessen, dass Hosts keinen Zugriff auf mysql erlauben sollten (entweder nur über localhost oder auf einem privaten internen LAN, so dass nur die Server darauf zugreifen können Ihr Netzwerk würde also auf vielen Hosts nicht funktionieren (oder sollte es wirklich nicht). –

Antwort

3

Ihr Problem ist, dass Sie mehrere Abfragen in Ihrer $sql String haben.

Ändern mysqli_query($con, $sql) zu mysqli_multi_query($con, $sql) und alles wird gut.

+0

ausgezeichnet. Vielen Dank. – Benza

Verwandte Themen