P
Pen Ttt
there is a section of my program,it can run,
require 'mysql'
dbh =3D Mysql.real_connect("localhost", "root", "222222")
days.times do #days=3D10000
case code
when "hk" then
str=3D"use dzh_hk"
dbh.query(str)
str_insert=3D"insert into quote (code,date,price)values (?,?,?)
st=3Ddbh.prepare(str_insert)
st.execute(data[0],data[1],data[2])
when "sh" then
str=3D"use dzh_sk"
dbh.query(str)
str_insert=3D"insert into quote (code,date,price)values (?,?,?)
st=3Ddbh.prepare(str_insert)
st.execute(data[0],data[1],data[2])
when "sz" then
str=3D"use dzh_sz"
dbh.query(str)
str_insert=3D"insert into quote (code,date,price)values (?,?,?)
st=3Ddbh.prepare(str_insert)
st.execute(data[0],data[1],data[2])
end
end
#others ommitted
i feel it's burdensome=EF=BC=8Cwant to make it be concise, i writ a m=
ethod
in my program
p1:
require 'mysql'
days.times do
def myinsert(code,data)
dbh =3D Mysql.real_connect("localhost", "root", "222222")
str=3D"use dzh_"+code
dbh.query(str)
str_insert=3D"insert into quote (code,date,price)values (?,?,?)
st=3Ddbh.prepare(str_insert)
st.execute(data[0],data[1],data[2])
end
end
#others ommitted
Mysql::Error: Too many connections
p2:
require 'mysql'
dbh =3D Mysql.real_connect("localhost", "root", "222222")
days.times do
def myinsert(code,data)
str=3D"use dzh_"+code
dbh.query(str)
str_insert=3D"insert into quote (code,date,price)values (?,?,?)
st=3Ddbh.prepare(str_insert)
st.execute(data[0],data[1],data[2])
end
end
#others ommitted
NameError: undefined local variable or method `dbh' for main:Object
would you mind tell me to write a right method to make it be concise?
-- =
Posted via http://www.ruby-forum.com/.=
require 'mysql'
dbh =3D Mysql.real_connect("localhost", "root", "222222")
days.times do #days=3D10000
case code
when "hk" then
str=3D"use dzh_hk"
dbh.query(str)
str_insert=3D"insert into quote (code,date,price)values (?,?,?)
st=3Ddbh.prepare(str_insert)
st.execute(data[0],data[1],data[2])
when "sh" then
str=3D"use dzh_sk"
dbh.query(str)
str_insert=3D"insert into quote (code,date,price)values (?,?,?)
st=3Ddbh.prepare(str_insert)
st.execute(data[0],data[1],data[2])
when "sz" then
str=3D"use dzh_sz"
dbh.query(str)
str_insert=3D"insert into quote (code,date,price)values (?,?,?)
st=3Ddbh.prepare(str_insert)
st.execute(data[0],data[1],data[2])
end
end
#others ommitted
i feel it's burdensome=EF=BC=8Cwant to make it be concise, i writ a m=
ethod
in my program
p1:
require 'mysql'
days.times do
def myinsert(code,data)
dbh =3D Mysql.real_connect("localhost", "root", "222222")
str=3D"use dzh_"+code
dbh.query(str)
str_insert=3D"insert into quote (code,date,price)values (?,?,?)
st=3Ddbh.prepare(str_insert)
st.execute(data[0],data[1],data[2])
end
end
#others ommitted
Mysql::Error: Too many connections
p2:
require 'mysql'
dbh =3D Mysql.real_connect("localhost", "root", "222222")
days.times do
def myinsert(code,data)
str=3D"use dzh_"+code
dbh.query(str)
str_insert=3D"insert into quote (code,date,price)values (?,?,?)
st=3Ddbh.prepare(str_insert)
st.execute(data[0],data[1],data[2])
end
end
#others ommitted
NameError: undefined local variable or method `dbh' for main:Object
would you mind tell me to write a right method to make it be concise?
-- =
Posted via http://www.ruby-forum.com/.=