2016-03-05 80 views
0

我有一個小問題,使用PHP,MySQL和查詢:插入到一個查詢(字符串)到多個表

這是我的查詢:

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")

insert into scheduleevent (rowid, refrowid, fromdate, todate, description) values (702,494,"2016-03-10 00:00:00","2016-03-11 00:00:00","Moni(cz)ka")

我想用mysql_query()來執行這個查詢。但執行後mysql_error()返回該錯誤

東西是錯在你的語法obok '插入scheduleevent(ROWID,refrowid,沒有fromdate,TODATE,描述)值' W linii 1

當我嘗試執行此查詢到phpmyadmin一切都OK。 我很困惑,請幫助我。

+0

使用'mysqli'嘗試 - 尤其是'mysqli_multi_query' – RamRaider

回答

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) 
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" 
); 
相關問題