designergav Posted January 4, 2007 Share Posted January 4, 2007 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.ThanksGav :) Link to comment https://forums.phpfreaks.com/topic/32852-getting-xml-data-into-phpmysql/ Share on other sites More sharing options...
trq Posted January 4, 2007 Share Posted January 4, 2007 Take a look at the man entry for the [url=http://php.net/xml]xml[/url] extesion, its really quite easy to parse xml. Link to comment https://forums.phpfreaks.com/topic/32852-getting-xml-data-into-phpmysql/#findComment-152930 Share on other sites More sharing options...
designergav Posted January 4, 2007 Author Share Posted January 4, 2007 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.CheersGav Link to comment https://forums.phpfreaks.com/topic/32852-getting-xml-data-into-phpmysql/#findComment-152954 Share on other sites More sharing options...
designergav Posted February 2, 2007 Author Share Posted February 2, 2007 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.ThanksDesignerGav Link to comment https://forums.phpfreaks.com/topic/32852-getting-xml-data-into-phpmysql/#findComment-175369 Share on other sites More sharing options...
designergav Posted February 2, 2007 Author Share Posted February 2, 2007 I've now got a script to read a csv file and insert the info into a mysql tableThe 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] Link to comment https://forums.phpfreaks.com/topic/32852-getting-xml-data-into-phpmysql/#findComment-175434 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.