# Parse xml file, put results in mysql db

**URL:** <https://www.ruby-forum.com/t/parse-xml-file-put-results-in-mysql-db/76172>\
**Category:** Ruby\
**Created:** [November 16, 2006, 1:36pm UTC](https://www.ruby-forum.com/t/parse-xml-file-put-results-in-mysql-db/76172 "2006-11-16T13:36:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kathys39](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ebca7d/32.png) [@kathys39](https://www.ruby-forum.com/u/kathys39)\
**Post date:** [November 16, 2006, 1:36pm UTC](https://www.ruby-forum.com/t/parse-xml-file-put-results-in-mysql-db/76172/1 "2006-11-16T13:36:37Z")

</div>

I’m a ruby newbie, parsing an xml file and putting results in mysql  
file. Working on linux. I can parse the data and print it out ok.  
Problem comes when I try to insert it into the mysql db - I get an error  
for the variables.

Here’s how I’m grabbing the data from xml and assigning to variable:  
doc.elements.each(“elementname”) { |element| puts  
element.attributes[“args”]  
args = element.attributes[“args”}…

That works fine. Below is the db stuff - can anyone figure out what I’m  
doing wrong?

dbname = “data”  
m = Mysql.new(“localhost”, “userid”, “passwd”)  
dbh = DBI.connect(“dbi:Mysql:data:localhost”, “userid”, “passwd”)  
m.select\_db(dbname)  
sth=dbh.prepare(“INSERT INTO rawdata (file, tool, arguments) VALUES  
(?,?,?)”)  
sth.execute("#{filename}", “#{toolname}”, “#{args}” )

The last line is where it fails - if I put in values, it works fine, so  
I know the error is in my variables. This is first time I"ve programmed  
ruby, so I’m not sure what is wrong…
