nezbo Posted November 16, 2007 Share Posted November 16, 2007 Hi all I am trying to undestand XML and the resion for it and if i should be using XML to send info from the PHP web page to mySQL database. if so how would i send for example $xml = mysql_query("INSERT data WHERE stuff = stuff"); please excuse the bad code. in an XML to database... Neil Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 16, 2007 Share Posted November 16, 2007 as an example $xmlString = "<xml..."; $xml = mysql_query("INSERT into XMLDATATABLE (data) values ('$xmlString')"); where XMLDATATABLE is the name of your mysql table data is the fieldname you should also use mysql_real_escape on the $xmlString Quote Link to comment Share on other sites More sharing options...
nezbo Posted November 16, 2007 Author Share Posted November 16, 2007 Cool Cheers so i need to get php to create an XML file first before i can insert it? is it good practise to use XML? if so what are the advantages. Neil as an example $xmlString = "<xml..."; $xml = mysql_query("INSERT into XMLDATATABLE (data) values ('$xmlString')"); where XMLDATATABLE is the name of your mysql table data is the fieldname you should also use mysql_real_escape on the $xmlString Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 16, 2007 Share Posted November 16, 2007 well as to my knowlegde xml is good for transport of structured data from one server to another it depends on your need what exactly you want I would not recommend inserting xml into a database (You should extract data from the xml and insert it into required fields) so its easy to query ( The whole concept of using a datatabase) Quote Link to comment Share on other sites More sharing options...
nezbo Posted November 16, 2007 Author Share Posted November 16, 2007 i think i am starting to undestand why i need to use XML so if i use :: $xml = mysql_query"SELECT * FROM XMLTABLE"; what should i be using insted with XML, or to dring back an XML, or to display an XML on my page? sorry to be a pest but i am just trying to get my head round it... Cheers, Neil well as to my knowlegde xml is good for transport of structured data from one server to another it depends on your need what exactly you want I would not recommend inserting xml into a database (You should extract data from the xml and insert it into required fields) so its easy to query ( The whole concept of using a datatabase) Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 16, 2007 Share Posted November 16, 2007 supposing you have the xml document <?xml version="1.0" encoding="ISO-8859-1" ?> - <!-- Edited with XML Spy v2007 (http://www.altova.com) --> - <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> you should have a table with fileds (to, from, heading,body) so basically your insert statement would be $xml = mysql_query("INSERT into XMLDATATABLE (to,from,heading,body) values ('Tove','Jani','Reminder','Don\'t forget me this weekend!</')"); so you can query the database on any of the fields consider the following select * from XMLDATATABLE where to='tove' would be easier to query than putting the actual xml code into the database I hope it helps Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.