2017-07-01 36 views
0

我試過MySQL插入查詢不工作並顯示錯誤「Database_Exception [1241]:操作數應該包含1列S)」。MYSQL INSERT QUERY NOT WORKING SHOWING ERROR「Database_Exception [1241]:操作數應該包含1列」

====> INSERT QUERY

INSERT INTO `notifications` (`message`, `selected_numbers`, `creation_date`, `update_date`, `message_date`) 
    VALUES ('hello testing', 
       ('32', '655', '203', '205', '204', '202', '12', '497', '123', '949', '77', '942', '937', '944', '953', '565', '652', '440', '826', '290', '20', '172', '23', '271', '648', '91', '89', '90', '450', '92', '31', '770', '766', '734', '776', '376', '403', '66', '977', '616', '65', '379', '323', '841', '745', '428', '544', '22', '831', '787'), 
       1498889053, 1498889053, '07/01/2017'); 

我試圖在通數組值來插入單個記錄。 但這個查詢不起作用。

回答

0

我猜你想要列表中的每個元素進入一個單獨的行,其他4列是相同的。如果是這樣,你可以在子查詢中使用insert . . . select並生成行:

INSERT INTO `notifications` (`message`, `selected_numbers`, `creation_date`, `update_date`, `message_date`) 
    SELECT 'hello testing', sn.selected_number, 
      1498889053, 1498889053, '2017-07-01' 
    FROM (SELECT '32' as selected_number UNION ALL 
      SELECT '655' UNION ALL 
      . . . 
      SELECT '787' 
     ) sn 
0

INSERT INTO notificationsmessageselected_numberscreation_dateupdate_datemessage_date) VALUES( '你好測試', ('32 '','655','203','205','204','202','12','497','123','949','77','942','937' '944','953','565','652','440','826','290','20','172','23','271','648','91 '','89','90','450','92','31','770','766','734','776','376','403','66', '977','616','65','379','323','841','745','428','544','22','831','787'), 1498889053,1498889053,'07/01/2017');

而不是做這個查詢,只是排除'selected_numbers'的數組並執行下面的查詢。

代碼

$ notifications_id = Model_Notifications ::刀片($ validatedValues-> as_array());

查詢

INSERT INTO notificationsmessagecreation_dateupdate_datemessage_date) VALUES( '你好測試',1498889053,1498889053,'07/01/2017' );

然後用於存儲'selected_numbers'數組創建一個新表並將其存儲在上面執行的查詢的主鍵上。

代碼

foreach ($phonenumber_value as $phone_id){ 
       Model_Notifications::notifications($phone_id, $notifications_id); 
      } 
相關問題