2017-07-01 4 views
0

MySQL挿入クエリが動作していないと表示されているエラー "Database_Exception [1241]:オペランドには1列s)」と表示されます。MYSQL INSERT QUERY ERRORを表示していません "Database_Exception [1241]:オペランドに1列が含まれている必要があります"

====> INSERTクエリ

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'); 

Iは、パスアレイ値に単一のレコードを挿入しようとしています。 このクエリは機能しません。

答えて

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 VALUES( 'ハローテスト'、notificationsmessageselected_numberscreation_dateupdate_datemessage_date)INTO ('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」 「67」、「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 notificationsmessagecreation_dateupdate_datemessage_date) 値に( 'ハロー試験'、1498889053、1498889053、'07/01/2017' )。

次に、 'selected_numbers'配列を格納するために、新しいテーブルを作成し、上記の実行されたクエリの主キーに対して格納します。

コード

foreach ($phonenumber_value as $phone_id){ 
       Model_Notifications::notifications($phone_id, $notifications_id); 
      } 
関連する問題