Jump to content

getting xml data into php/mysql


designergav

Recommended Posts

Hi all. Just when I think I've learnt enough to cope another comes something else. I'm just a designer but everyone seems to think I can develop. Which is ok. Mostly. This though is causing me to go a bit doolally.

I've got an xml file that contains amongst others the element <currency> which contains these childs. <cname><csymbol><crate>. There are nearly 200 <currency>. I need to use XPath (although I've no idea how ???) to extract those values so that I can insert the whole lot into a mysql db. I will then call the relevant data back to my webpages when required.

The xml file will be purchased as a licensed file so I can't touch it in any way or move it so I need to refer to it where it is. I'll need to run cron job or windows scheduler to run my script on a daily basis.

Any help would be great as I'm currently having to manually update my fields. >:(

Oh and my web server is only running php4.
Thanks
Gav  :)
Link to comment
https://forums.phpfreaks.com/topic/32852-getting-xml-data-into-phpmysql/
Share on other sites

I've just had a look at that and now I'm even more confused. I like to think I can learn uqickly and pick things up easily but this is baffling me. I find one bit to try and it just creates more problems.

SimpleXML was going great until I found out the web server is only running php4. ADO_DB classes seemed easy to follow but don't want to read my xml file. I'm sure I can work out to to read the xml file but that's only the beginning, I need to create an array of some sort so that I can then put all the values into mysql.

I didn't even want to be a programmer  :'(

Still knowldege is power. Apparently.
Cheers
Gav
  • 4 weeks later...
I've got a script to read my csv file and I've run some str_replace to get the formating required to insert into mysql table.

The problem is i get an error inserting. I think it is because there is extra text at the start that doesn't match my insert command. I'm inserting using this:
[code]
$sql = "INSERT into currencies (csymbol, cname, crate) VALUES $singlequotes";
[/code]
where $singlequotes is my csv string. The first part of the string contains info I don't need and may be causing the INSERT to fail. It ends with:

('Days until new access period begins','1'),('UTC Timestamp','2005.01.09 17:00:00'),('Local Timezone','GMT'),('Local Timestamp','2005.01.09 17:00:00'),('Base Currency','GBP'),

How can I remove this beginning of the string so that it start with the next bit:
('AED','United Arab Emirates Dirhams','6.8712288192'),('AFA','Afghanistan Afghanis','80.0505170552'),('ALL','Albania Leke','180.5912341387')

The problem is that the text in the first part will change each time I run the script, although the format is always the same.

I'm still fairly new to php so any help would be great.
Thanks
DesignerGav
I've now got a script to read a csv file and insert the info into a mysql table

The file I'm reading for testing is in the same web directory as the script and this works file:
[code]
$filename = "/filetoread.csv";
$fd = fopen ($filename, "r");
$contents = fread ($fd,filesize ($filename));
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.