I want to update my local.xml with script. I want to change my username , database name and password in the xml using my custom script. I am creating script. it can show the values of the node and also update the values but it can't set CDATA with the values in the node code:-
$xml = simplexml_load_file('app/etc/local.xml'); // connection details are inside of CDATA
$conn = $xml->global->resources->default_setup->connection;
echo $user = $conn->username;
$pass = $conn->password;
$pass = $conn->dbname;
// create CDATA section
echo $conn->username = '<'.'![CDATA['.'user'.']]'.'>';
echo $conn->password = '<'.'![CDATA['.'pass'.']]'.'>';
echo $conn->dbname = '<'.'![CDATA['.'bdname'.']]'.'>';
$xml->asXML('app/etc/local.xml');
I want to add CDATA with my values in the xml. like this
<connection>
<host><![CDATA[localhost]]></host>
<username><![CDATA[root]]></username>
<password><![CDATA[ghrix321]]></password>
<dbname><![CDATA[bachatbay]]></dbname>
<initStatements><![CDATA[SET NAMES utf8]]></initStatements>
<model><![CDATA[mysql4]]></model>
<type><![CDATA[pdo_mysql]]></type>
<pdoType><![CDATA[]]></pdoType>
<active>1</active>
</connection>
Please suggest me , what can i do ?
Try this below code, and alter whatever you want.
Note: You can get any nodes by iterating like object and arrays.