Mysq connection fails

Hi,

I have a small utility script that should grab some data from a mysql
database and then do stuff with it. It’s working on Mac OS 10.4 (with
mysql 4.something) but fails on the linux server that it’s supposed to
be deployed on which from memory is running mysql 3.23 (or there
abouts). Oh, to make matters worse, my mac is running ruby 1.8.4 and the
server is 1.8.2.

One other difference is that I can’t install the gem properly on the
linux box as I don’t have the right privledges, so the mysql lib is
being referenced as a file in the same directory. This seems to work, as
I can load a Mysql class ok and check out it’s functions.

The linux server seems to fail on the Mysql.rel_connect call, but
doesn’t get to the rescue - it fails in the ensure block with no method
error on dbh.close (dbh is nil).

Can anyone offer any advice on where to look - I know it’s a bit messy,
but I’m sure there’s some magic that can be done to get it working!

By the way, I can’t get the mysql version on the linux server updated as
it’s a shared server (but may be able to upgrade ruby to 1.8.4).

thanks,
Dan

code snippet

require “mysql”

begin

connect to the MySQL server

dbh = Mysql.real_connect(“localhost”, “user”, “password”, “db”)
#nothing happens after here

res = dbh.query(“SELECT * FROM pages”)

while row = res.fetch_row do
home_stats << sprintf("%-1$*3$s %2$d\n", row[0], row[1].to_i,
40)
home_total += row[1].to_i
end

res.free

rescue MysqlError => e
puts “error: #{e}” # <-- this line never gets called even though dbh
is nil

ensure

disconnect from server

dbh.close # <-- fails here because dbh is nil
end

Raja Venkataraman wrote:

Can you try and connect to mysql from the command line? the above
connect string seems very basic with no extra arguments, so you should
be able to try out a
mysql -u -p -h localhost db
and see if you can get through that.

command line works ok…

Daniel G. wrote:

code snippet

require “mysql”

begin

connect to the MySQL server

dbh = Mysql.real_connect(“localhost”, “user”, “password”, “db”)
#nothing happens after here

Can you try and connect to mysql from the command line? the above
connect string seems very basic with no extra arguments, so you should
be able to try out a
mysql -u -p -h localhost db
and see if you can get through that.