L
Luis Moran
Hello,
I am new in ruby and have a little problem.... I have the following code
class Grid
attr_accessor :host
...
attr_accessor :connection
def initialize (host, user, passwd, dbname)
@host = host
@user = ...
end
def connect
@connection = Mysql.real_connect(@host, @user, @passwd, @dbname)
if @connection then
puts "connected"
end
end
def query
res = @connection.query("select * from table")
return res
end
end
and now from a script
require "the clash file"
db = Grid.new("localhost","user","password","db")
db.connect
db.query
and I get an error cause the database seem to be closed... or which is
the same @connection is null? I only can make it work if I open and
close the database from inside the query method, but this query is
called more than 4000 times in the script and I reach the limit of
connections of my system's TCP/IP
Anyone could help me? I don't understand why I can share @host, @user
and the other attributes among the methods but @connection seems to be
lost.
thanks in advance.
I am new in ruby and have a little problem.... I have the following code
class Grid
attr_accessor :host
...
attr_accessor :connection
def initialize (host, user, passwd, dbname)
@host = host
@user = ...
end
def connect
@connection = Mysql.real_connect(@host, @user, @passwd, @dbname)
if @connection then
puts "connected"
end
end
def query
res = @connection.query("select * from table")
return res
end
end
and now from a script
require "the clash file"
db = Grid.new("localhost","user","password","db")
db.connect
db.query
and I get an error cause the database seem to be closed... or which is
the same @connection is null? I only can make it work if I open and
close the database from inside the query method, but this query is
called more than 4000 times in the script and I reach the limit of
connections of my system's TCP/IP
Anyone could help me? I don't understand why I can share @host, @user
and the other attributes among the methods but @connection seems to be
lost.
thanks in advance.