How to insert null values into a data list?

Asked

Viewed 86 times

-1

I believe the problem is here:

'tlkc_conversation_2' => '',

I am trying to enter data in the database, but some fields are null, and I am receiving the following message:

Illuminate Database Queryexception : SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column Count doesn’t match value Count at Row 3 (SQL: Insert into talk_conversation (tlk_id, tlkc_conversation_1, tlkc_conversation_2, tlkc_created, tlkc_order, tlkc_person_1, tlkc_user_option) values (34, Hello! This week we’ll talk a little bit about pandemics and try understand a little better what we are living in today’s world. How you know, we’re going through an unusual situation, caused by coronavirus. This virus appeared in China in December 2019, and in March 2020, the disease caused by it, called COVID-19, was considered a pandemic by the World Health Organization (WHO). A transmission of the disease occurs by air or by contact with secretions contaminated, like sneezing, coughing and phlegm. Yes, I know that. What I don’t know what usually changes with this new classification..., 2020-04-27 10:50:31, 1, 12, 2), (34, Come on. It’s nice to remember that a pandemic is far from seeming something without control. Nor does it mean that in such a case the measures taken are inefficient, or there is more to do. A pandemic is defined when a disease infectious spreads and simultaneously reaches a large number of people all over the world! That’s what determines it. Oh, I got it! So means that the fact that a disease becomes a pandemic does not means it changes the way it proliferates and us care, right? , 2020-04-27 10:50:31, 2, 12, 2), (34, exactly! We must always remember that we all integrate humanity, and by the fact that the disease is global, it is important to think collectively to stop the spread of contagions. Bearing this in mind, you have a challenge ahead: read three texts, respond to the Quiz and unravel the mystery of this week. Good work! , 2020-04-27 10:50:31, 3, 12, 2))

  $id_background_dialog_1 = 34;

   $person_1 = 12;
   $person_2 = null;

  $fase1 = [
             [
                 'tlk_id' => $id_background_dialog_1, 
                 'tlkc_order' => 1, 
                 'tlkc_conversation_1' => 'Olá! Nesta semana vamos falar um pouquinho sobre pandemias e tentar entender um pouco melhor o que estamos vivendo no mundo de hoje. Como você sabe, estamos passando por uma situação incomum, causada pelo coronavírus.  Esse vírus surgiu na China, em dezembro de 2019, e, em março de 2020, a doença causada por ele, chamada de COVID-19, foi considerada uma pandemia pela Organização Mundial da Saúde (OMS). A transmissão da doença ocorre pelo ar ou por contato com secreções contaminadas, como espirro, tosse e catarro.', 
                 'tlkc_conversation_2' => 'Sim, isso eu sei. O que eu não sei é o que geralmente muda com essa nova classificação...', 
                 'tlkc_person_1' => $person_1, 
                 'tlkc_person_2' => $person_2, 
                 'tlkc_created' => date('Y-m-d H:i:s'), 
                 'tlkc_updated' => null, 
                 'tlkc_timeout_1' => null, 
                 'tlkc_timeout_2' => null, 
                 'tlkc_picture_1' => null,
                 'tlkc_picture_2' => null, 
                 'tlkc_user_option' => 2
             ],
             [
                 'tlk_id' => $id_background_dialog_1, 
                 'tlkc_order' => 2, 
                 'tlkc_conversation_1' => 'Vamos lá. É legal lembrar que uma pandemia está longe de parecer algo sem controle. Também não significa que nesse caso as medidas tomadas são ineficientes, ou ainda que não há mais o que fazer. Uma pandemia é definida quando uma doença infecciosa se propaga e atinge simultaneamente um grande número de pessoas em todo o mundo! É isso o que a determina.', 
                 'tlkc_conversation_2' => 'Ah, entendi! Então quer dizer que o fato de uma doença se tornar uma pandemia não significa que muda a forma de ela se proliferar e de nós nos cuidarmos, certo?', 
                 'tlkc_person_1' => $person_1, 
                 'tlkc_person_2' => $person_2, 
                 'tlkc_created' => date('Y-m-d H:i:s'), 
                 'tlkc_updated' => null, 
                 'tlkc_timeout_1' => null, 
                 'tlkc_timeout_2' => null, 
                 'tlkc_picture_1' => null,
                 'tlkc_picture_2' => null, 
                 'tlkc_user_option' => 2
             ],
             [
                 'tlk_id' => $id_background_dialog_1, 
                 'tlkc_order' => 3, 
                 'tlkc_conversation_1' => 'Exatamente! Devemos sempre lembrar que todos nós integramos a humanidade, e, pelo fato de a doença ser de alcance global, é importante pensar coletivamente para frear o avanço dos contágios. Tendo isso em mente, você tem um desafio pela frente: ler três textos, responder ao Quiz e desvendar o mistério desta semana. Bom trabalho!', 
                 'tlkc_conversation_2' => '', 
                 'tlkc_person_1' => $person_1, 
                 'tlkc_person_2' => $person_2, 
                 'tlkc_created' => date('Y-m-d H:i:s'), 
                 'tlkc_updated' => null, 
                 'tlkc_timeout_1' => null, 
                 'tlkc_timeout_2' => null, 
                 'tlkc_picture_1' => null,
                 'tlkc_picture_2' => null, 
                 'tlkc_user_option' => 2
             ]
         ];

 DB::table('talk_conversation')->insert(
             $fase1
         );

Table:

CREATE TABLE `talk_conversation` (
  `tlkc_id` int(11) NOT NULL AUTO_INCREMENT,
  `tlk_id` int(11) DEFAULT NULL,
  `tlkc_order` int(2) DEFAULT NULL,
  `tlkc_conversation_1` text,
  `tlkc_conversation_2` text,
  `tlkc_person_1` int(1) DEFAULT NULL,
  `tlkc_person_2` int(1) DEFAULT NULL,
  `tlkc_created` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `tlkc_updated` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `tlkc_timeout_1` int(3) DEFAULT NULL,
  `tlkc_timeout_2` int(3) DEFAULT NULL,
  `tlkc_picture_1` varchar(300) DEFAULT NULL,
  `tlkc_picture_2` varchar(300) DEFAULT NULL,
  `tlkc_user_option` int(1) DEFAULT NULL,
  PRIMARY KEY (`tlkc_id`),
  KEY `talk_id_idx` (`tlk_id`)
) ENGINE=InnoDB AUTO_INCREMENT=41 DEFAULT CHARSET=latin1;

1 answer

1

  • So, but I made a method that does this, see in this example:https://ideone.com/yHytJc, but still it was wrong, when I want to fill empty field, without being null, as I do?

  • I will try to explain to you: NULL is a type of record, EMPTY are various types of record. NULL is part of the EMPTY records, but the other EMPTY record types are different from NULL. The NULL value does not need data to represent it in memory, but "", 0 , FALSE .... all others do. You can use in your if: 1. EMPTY($data[$this->key]) to test if it is empty ( this includes testing 0, FALSE, "", NULL....) 2. IS_NULL($data[$this->key]) to test if it is only NULL.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.