what's proble with ruby-mysql-prepare?

P

Pen Ttt

when i run p1 ,i can get something like:
Zimmer Holdings, Inc.
Zion Oil & Gas Inc
Zions Bancorporation
Zions Bancorporation
Zions Bancorporation
Zions Bancorporation
Zweig Fund, Inc. (The)
Zweig Total Return Fund, Inc. (The)
p1:
require 'rubygems'
require 'mysql'
file=open('/home/pt/usastock/nasdaqcompanylist.csv','r')
dbh = Mysql.real_connect("localhost", "root", "*****", "usastock")
while line=file.gets
line=line.chomp.split("\"")
print line[3],"\n"
end

when i run p2,i can get nothing ,what's wrong?
p2:
require 'rubygems'
require 'mysql'
file=open('/home/pt/usastock/nasdaqcompanylist.csv','r')
dbh = Mysql.real_connect("localhost", "root", "*****", "usastock")
while line=file.gets
line=line.chomp.split("\"")
print line[3],"\n"
sqlstr="insert into nasdaqname(name) values (?);"
st=dbh.prepare(sqlstr)
st.execute(#{line[3]})
end
 
P

Pen Ttt

require 'rubygems'
require 'mysql'
file=open('/home/pt/usastock/nasdaqcompanylist.csv','r')
dbh = Mysql.real_connect("localhost", "root", "******", "usastock")
sqlstr="insert into nasdaqname(name) values (?);"
st=dbh.prepare(sqlstr)
while line=file.gets
line=line.chomp.split("\"")
print line[3],"\n"
st.execute(#{line[3]})
end

i can get nothing whit that too.
 
P

Pen Ttt

there two ways to do it after test
1.st.execute(line[3])
2.st.execute("#{line[3]}")
thinks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top