I’m using v2.5.2 of EE and getting a strange result on a simple update query, perhaps someone could shed some light on it.
Here is a the PHP code:
(string) $dBtable = "exp_channel_data INNER JOIN exp_channel_titles ON (exp_channel_data.entry_id = exp_channel_titles.entry_id)";
(string) $dBwhere = "exp_channel_data.site_id = $sid AND exp_channel_data.channel_id = $ch AND exp_channel_data.entry_id = $entry_id";
$data = array(
'status' => $e_status,
'edit_date' => $e_edit,
'title' => $e_title,
'field_id_53' => $e_answerer,
'field_id_76' => $e_material,
'field_id_51' => $e_question,
'field_id_52' => $e_answer,
'field_id_62' => $e_general_answer
);
$sql = $this->EE->db->update_string( $dBtable, $data, $dBwhere );
$query = $this->EE->db->query( $sql );
$res = $this->EE->db->affected_rows();
...check results and output XML.The php variables should be self evident, the $e_ vars are for post data. Notice I am only updating a record that already exists in the channel and using the exp_channel_data and exp_channel_titles tables.
The strange part is the update query should have no effect on the categories for the entry (because they are kept in the exp_category_posts table) and yet for some reason when the query is run it wipes out all the categories that where assigned to the entry???
Is this some sort of undocumented EE feature when updating content in the exp_channel_data and exp_channel_titles tables? I’ve never run accross anything like this before using the EE classes.
If this behaviour was documented I’d understand, but I can’t find anything about it. I will probably switch the code over to using the Channel Entries API, however, that method is much more complicated to use vs. a simple update query (when you’re only changing a few fields data). I usually only use the Channel Entries API when adding new records.
I’m not sure I like the idea of some behind the scene manipulation of table data when performing what should be straight sql queries - makes me want to consider not to use the EE classes.
Any light that can be shed on this behaviour would be helpful, maybe I missed something here.
Thank You,
-Jon