Jump to content

PHP and XML Help


nezbo

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.