Problem connecting to MySQL with eRuby
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 fai开发者_JS百科ls.
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
if message is Access denied
check the username, password, host, and port!
精彩评论