将一个查询(字符串)插入到许多表中

时间:2016-03-05 09:07:35

标签: php mysql

我对php,mysql和query有一个小问题:

这些是我的疑问:

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>TestWeb2</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <servlet> <description></description> <display-name>MyServlet</display-name> <servlet-name>MyServlet</servlet-name> <servlet-class>servlets/MyServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>MyServlet</servlet-name> <url-pattern>/MyServlet</url-pattern> </servlet-mapping> </web-app>

insert into schedule (rowid, parentrowid, sortIndexProj, sortindex, projectnummer, recordtype, refrecid, description, specialrow) values (451,451,0,1,243,10,243,"",0),(494,451,0,2,243,70,17,"",0);

insert into scheduleevent (rowid, refrowid, fromdate, todate, description) values (533,451,"2016-04-06 00:00:00","2016-04-07 00:00:00","Start week 14 t/m 40 Hoofdleidingen gereed week 24"),(571,451,"2016-03-29 00:00:00","2016-03-30 00:00:00","BAM-EDU transport")

我想使用mysql_query()执行此查询。但执行mysql_error()后返回此错误

  

你的语法obok'插入scheduleevent(rowid,refrowid,fromdate,todate,description)值有问题'w linii 1

当我尝试将此查询执行到phpmyadmin时,一切正常。 我很困惑,请帮助我。

2 个答案:

答案 0 :(得分:0)

使用以下语法:

INSERT ALL
  INTO mytable (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
  INTO mytable (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
  INTO mytable (column1, column2, column_n) VALUES (expr1, expr2, expr_n)

答案 1 :(得分:0)

Add a semicolon to your second query and try it:

INSERT INTO scheduleevent (
    rowid,
    refrowid,
    fromdate,
    todate,
    description
) values (
    533,
    451,
    "2016-04-06 00:00:00",
    "2016-04-07 00:00:00",
    "Start week 14 t/m 40 Hoofdleidingen gereed week 24"
),(
    571,
    451,
    "2016-03-29 00:00:00",
    "2016-03-30 00:00:00",
    "BAM-EDU transport"
);