There is a php function in which switch ... if you need to create news, then ... create 2 tables and fill it with contents. The problem is that the tables are created, but not filled with information. What's the matter?

function createModule($Module){ switch($Module){ //Модуль Новости case "news": mysql_query(" CREATE TABLE IF NOT EXISTS `mynewtable_news` ( `item` VARCHAR( 256 ) NOT NULL, `name` VARCHAR( 256 ) NOT NULL, `active` BOOLEAN NOT NULL DEFAULT 0 COMMENT 'Активация', `necessary` BOOLEAN NOT NULL DEFAULT 0 COMMENT 'Обязательное поле' ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci COMMENT 'Модуль Новости'; "); //Заполняем предыдущую таблицу mysql_query(" INSERT INTO `mynewtable_news` VALUES('id', 'ID', '1', '1' ); INSERT INTO `mynewtable_news` VALUES('title', 'Название', '1', '1' ); "); //Составляющие новостей mysql_query(" CREATE TABLE IF NOT EXISTS `mynewtable_news_components` ( `component` VARCHAR( 256 ) NOT NULL , `name` VARCHAR( 256 ) NOT NULL , `active` BOOLEAN NOT NULL DEFAULT 0 COMMENT 'Активация' ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci COMMENT 'Составляющие новостей'; "); //Заполняем предыдущую таблицу mysql_query(" INSERT INTO `mynewtable_news_components` VALUES('category', 'Категории', '1'); INSERT INTO `mynewtable_news_components` VALUES('comments', 'Комментарии', '1'); "); break; }; 

};

    3 answers 3

    Not special in PHP, but in my opinion, 2 requests to thrust into one mysql_query () - crazy.

    In any case, you should always check whether the query was executed without errors or not. An example can be found at the link:

    Link to Russian documentation

      And who said that mysql_query can execute multiple queries at once?

      Either do it in a loop, or use mysqli_multi_query

      • thanks, now I will try - informals

      http://docs.php.net/manual/ru/function.mysql-query.php

      mysql_query() sends one request (sending multiple requests is not supported) to the active database of the server referenced by the transmitted link_identifier handle.

      One request is as follows:

      one:

       INSERT INTO `mynewtable_news` (item, name, active, necessary) VALUES ('id', 'ID', '1', '1' ), ('title', 'Название', '1', '1'); 

      2:

       INSERT INTO `mynewtable_news_components` (component, name, active) VALUES ('category', 'Категории', '1'), ('comments', 'Комментарии', '1'); 
      • Yes, it is possible .. But the question was not about that :-D - Photon