My Issue: Unable to append XML data to prexisting XML data in a MYSQL database.
I have an array – $buyer. Inside this array is a $key and $value similar to (shippingTotal => 55). What I want to do is use something similar to
$param = array(
'shippingTotal' => $shippingTotal
);
$where['quote_data = ?'] = $quoteNumber
$n = $db->update('quote_xml', simplexml_load_string($param), $where);
My hiccup is that the current data inside quote_data is an XML element containing LOTS of information. Is there any way to just “stick” shippingTotal into said existing XML? When I use the above code I just end up with quote_data becoming empty.
I also created a variable called $shippingTotal so that I wouldn’t have to use $buyer[‘shippingTotal’]. Still not functional.
Thank you for your time and assistance with this issue.
Aaron
I see a few issues with this:
First,
simplexml_load_stringdoesn’t accept array parameters, only XML strings. Since the$paramsis not a valid argument, it is returning booleanfalse. Even when successful, it returns aSimpleXMLElement. To convert that to an XML string, you would have to call theasXML()method on the returned object before passing it toZend_Db_Table::update().Second, most likely XML cannot just be “appended” to other XML. I don’t know exactly what your table holds, but the XML needs to be programmatically added to the existing XML. You can’t append XML because the data you want to add needs to be added to the proper nodes.
What you will have to do is first read the value of that column, parse it using
SimpleXML, add your new data to the appropriate node in the document using one of the SimpleXML functions and then perform the update.Hope that helps.