From: zig Date: 2007-02-06T14:05:09+09:00 Subject: Re: mysql-ruby won't connect On Jan 28, 2:18 pm, "zig" wrote: > > Thanks for your help, Mat. This is pretty frustrating, so it's nice > to have people try to help. Unfortunately, this doesn't seem to have > helped me. Maybe our problems are different? Do you have any further > insight to share about that? I said that this workaround didn't fix things for me, but maybe it did. At this point, I'm a little foggy on which parts worked when, since I've only looked at this sporadically over the course of a couple of weeks. My test.rb unit testing still does not capture the login I hand it on the command line; that thing is not working. For a while, I thought I was still broken. I couldn't connect to the database in my rhtml file, so I figured that the problem with my test.rb meant that the software just isn't working on my system. Not so. I did notice that I _can_ connect in irb. In fact, my rhtml test file will connect to the database if I run eruby on it from the command line like # eruby db.rhtml When I discovered this, I realized that I must be closer to working than I thought. I googled the woefully uninformative error message from my apache log (and it's also worth pointing out that you can send that error right to the browser, rather than fishing it out of the apache error log, by encapsulating the mysql commands with some exception catching), that error again was /usr/local/apache2/htdocs/db.rhtml:13:in `real_connect': Can't connect to MySQL server on 'localhost' (49) (Mysql::Error) Some of the google hits indicated that this error means that the mysql.sock file was not found. Mysql#real_connect takes a parameter for the mysql.sock socket file. Specifying this in my rhtml file made everything work. In the end, my file looked like this: Eruby + mysql/ruby

This is a test of the mod_ruby/Eruby mysql/ruby c bindings (not the pure ruby plugin known as ruby/mysql)

<% require 'mysql' begin dbh = Mysql.real_connect("localhost", "root", "password", "test", 3306,'/tmp/mysql.sock') puts "Server version: " + dbh.get_server_info dbh.select_db("db") res = dbh.query("select * from table where id = 1") res.fetch_row().each {|i| puts i} rescue Mysql::Error puts $!.error end %> I guess I'm up and running now, so let me give thanks to the newsgroup for support, and especially to Mat for his help. And by the way, I don't remember completely, but I'm pretty sure that I couldn't get this far before I implemented Mat's fix. So I think that actually was the resolution of my problem, despite what I said above. Also, I still don't know why I have to specify the socket file within the Apache environment mod_ruby rhtml file, but not when running irb or eruby from the command line. Obvious some environment variable is different, which causes the socket file not to be found in the Apache environment. But which? I would like to figure that out too, it would be nice not to have to type that in, though it's not too important. I played around with the PATH variable, I don't think that's the problem. So feel free to shoot me the answer to that, if you have it. Otherwise, thanks again all.