1

I'm having a problem connecting my eRuby scripts to my MySQL database.

I've written a short test script just to work out the initial connection bugs:

<%

require 'mysql'

begin
     dbh = Mysql::new("localhost", "test", "wahssf", "amg")
rescue Mysql::Error => e
     print "Error code: #{e.errno}<br />"
     print "Error message: #{e.error}<br />"
     print "Error SQLSTATE: #{e.sqlstate}" if e.respond_to?("sqlstate")
ensure
     dbh.close if dbh
end

%>

Now, as long as I keep the connection parameters as gibberish ("test", "wahssf", "amg"), the script defaults to the Mysql::Error class and prints the following to the browser:

Error code: 1045
Error message: Access denied for user 'test'@'localhost' (using password: YES)
Error SQLSTATE: 28000

However, once I put in REAL connection values and reload the page, the script fails (for some reason?) and I get an HTTP 500 Internal Server Error.

I have absolutely no idea what the problem is. As long as the username/password combination is wrong, the script "works" but obviously doesn't connect, but as soon as I give it the proper credentials, it fails.

Any ideas?

Also, what's worth mentioning: When I execute this script by typing it in line by line via irb on the command prompt, it works. It only seems to be an issue in eRuby.

Vitals: Apache 2.2.8 running on Fedora Core 7 MySQL 5.0.* (gem mysql version 2.8.1) Ruby 1.9.2

Derrick T
  • 21
  • 1
  • Is there anything in the server logs? You could also try running this code from the command line and see if any errors are output there. – Jon Gauthier Apr 08 '11 at 02:47
  • `/ruby.rhtml:7:in 'close': wrong argument type Mysql (expected Struct) (TypeError)` I tried adding a query() method to dbh as well, with the same error being returned. – Derrick T Apr 08 '11 at 03:17
  • What if you say `dbh = Mysql.new` instead of `dbh = Mysql::new`? – mu is too short Apr 08 '11 at 03:20
  • The same error is reported to the logs as before. Why would it expect a type OTHER than Mysql for the methods that are part of the Mysql class? And what does type Struct refer to? I'm completely at a loss here :\ – Derrick T Apr 08 '11 at 03:33

1 Answers1

0

if message is Access denied check the username, password, host, and port!

Darlan Dieterich
  • 2,369
  • 1
  • 27
  • 37