使用 eRuby 连接 MySQL 时出现问题
我在将 eRuby 脚本连接到 MySQL 数据库时遇到问题。
我编写了一个简短的测试脚本,只是为了解决初始连接错误:
<%
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
%>
现在,只要我将连接参数保留为乱码(“test”、“wahssf”、“amg”),脚本默认为 Mysql::Error
类并将以下内容打印到浏览器:
Error code: 1045
Error message: Access denied for user 'test'@'localhost' (using password: YES)
Error SQLSTATE: 28000
但是,一旦我输入真实连接值并重新加载页面,脚本就会失败(出于某种原因?)并且我得到一个 HTTP 500内部服务器错误
。
我完全不知道问题是什么。只要用户名/密码组合错误,脚本就会“工作”,但显然无法连接,但一旦我给它正确的凭据,它就会失败。
有什么想法吗?
另外,值得一提的是:当我在命令提示符下通过 irb 逐行输入该脚本来执行该脚本时,它可以工作。这似乎只是 eRuby 中的一个问题。
命脉: Apache 2.2.8 在 Fedora Core 7 上运行 MySQL 5.0.*(gem mysql
版本 2.8.1) 红宝石 1.9.2
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果消息是
拒绝访问
,请检查用户名、密码、主机和端口!if message is
Access denied
check the username, password, host, and port!