dongluojiao6322 2017-07-17 11:09
浏览 38
已采纳

PHP - 创建多个表

I'm creating an installation page where the new user enters their database host, username, host and password. I have this done and it's working.

I need to make it so it creates a table.

I know how to do it but not with my whole sql export.

I need to insert my whole sql export into their database.

I'm getting an error on the line with online_users but I am not sure why.

My sql export is :

          $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', 'benzaofficial55@gmail.com', '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', 'benza@hotmail.com', '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', 'test@hotmail.com', '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条回答 默认 最新

  • dousheyan0375 2017-07-17 11:23
    关注

    Your problem is that you have multiple queries in your $sql string.

    Change mysqli_query($con, $sql) to mysqli_multi_query($con, $sql) and all will be fine.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 pycharm倒入虚拟环境的时候,显示这个,但是我的虚拟环境已经创建了
  • ¥15 FPGA芯片60进制计数器
  • ¥15 前端js怎么实现word的.doc后缀文件在线预览
  • ¥20 macmin m 4连接iPad
  • ¥15 DBIF_REPO_SQL_ERROR
  • ¥15 根据历年月数据,用Stata预测未来六个月汇率
  • ¥15 DevEco studio开发工具 真机联调找不到手机设备
  • ¥15 请教前后端分离的问题
  • ¥100 冷钱包突然失效,急寻解决方案
  • ¥15 下载honeyd时报错 configure: error: you need to instal a more recent version of libdnet
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部