1

So I have a custom plugin that inserts data from a csv. I build up the array of data and then issue the insert command.

Right before the insert I am dumping my array so I can see the values which are not encoded. This is what is displayed.

array(6) {
  ["entry_id"]=>
  string(4) "2642"
  ["site_id"]=>
  int(1)
  ["channel_id"]=>
  int(1)
  ["field_ft_5"]=>
  string(4) "none"
  ["field_id_5"]=>
  string(28) "17524.mp4"
  ["field_ft_6"]=>
  string(4) "none"
  ["field_id_6"]=>
  string(3) "30"
}

Then the exception shows the sql query that is built out and this is what the query looks like.

INSERT INTO `exp_channel_data` 
(`entry_id`, `site_id`, `channel_id`, `field_ft_5`, `field_id_5`, `field_ft_6`, `field_id_6`) 
VALUES 
('2642', 1, 1, 'none', '1\07\05\02\04\0.\0m\0p\04', 'none', '3\00')

 //

My code is right there is. Nothing in between my dump and my insert. I have done something similar to this in the past and never saw anything get encoded.

var_dump($channel_data);
$this->EE->db->insert('channel_data', $channel_data);

Any tips on where to look would be appreciated. I am on EE 3.5.6 with php 7.2.

Thanks

Edit 1 Here is what I am doing to build the array so I am not converting object to array that I am aware of.

// exp_channel_data
                        $channel_data = array(
                            'entry_id'      => $entry_id,
                            'site_id'       => $this->_site_id,
                            'channel_id'    => $this->_clip_channel_id
                        );


                        foreach($this->_clip_channel_fields as $clip_channel_field)
                        {

                            if( isset($clip_channel_field['field_name']) )
                            {

                                $field_id = 'field_id_' . $clip_channel_field['field_id'];
                                $field_ft = 'field_ft_' . $clip_channel_field['field_id'];

                                $channel_data[$field_ft] = $clip_channel_field['field_fmt'];
                                $channel_data[$field_id] = ${$clip_channel_field['field_name']};

                            }
                        }
  • This looks like an artifact of how you are converting to an array. See PHP documentation: php.net/manual/en/… (null bytes in the string just as in your example) – AllInOne Jan 30 '19 at 22:59
  • @AllInOne I agree it looks that way as well but I don't try to convert an object to an array anywhere that I see. I will try to dig deeper into it though. I also put an edit to show how I build the array. – Chris Jan 30 '19 at 23:15
  • Not sure if this has to do with it, but EE doesn't get php 7.2 compatibility until 3.5.13 – Romans-8---31-39 Jan 31 '19 at 17:13
  • Thanks. I upgraded locally to 3.5.17 and tried and didn't resolve it. I will plan on upgrading just in case though so thanks for pointing that out. – Chris Jan 31 '19 at 21:46
0

I'm not entirely sure why you are inserting raw data into a well-modeled object.

I would highly recommend you use the internal API for inserting new Channel Entries:

https://docs.expressionengine.com/latest/development/legacy/api/api_channel_entries.html

That would be the best way to take external data (say, via your plugin), and create a valid new Entry record. It seems like you are possibly creating invalid records by inserting rows this ways. You'll have to expand on exactly what your plugin does here for us to hone our answers.

| improve this answer | |
  • This is legacy code I took over but the process is a client uploads a csv. Then we take each row and create a record. Grab the id of the record and add the channel_data information. Lastly we we add the appropriate categories based on what was supplied in the csv. It had been working for years but was recently migrated to new servers with upgraded php and mysql and now is not working. Still guessing is has something to do with php upgrade. I will look at internal API as a solution. Thanks – Chris Feb 1 '19 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.