1
votes

Heads up, ruby n00b testing the waters -

OS - OSX 10.7

test.rb in /Library/WebServer/CGI-Executables:

#!/usr/bin/ruby
require 'mysql'

con = Mysql.new('localhost', 'root', 'root', 'rubytest')
rs = con.query('select * from people')
rs.each_hash { |h| puts h['name']}  
con.close

When running from the command line ruby test.rb, I get the fields within just fine. When hitting test.rb from localhost (http://localhost/cgi-bin/test.rb), I get a 500 and a nag in the error log about mysql being missing-

Apache error log:

[Fri Aug 31 23:47:22 2012] [error] [client 127.0.0.1] /Library/WebServer/CGI-Executables/test.rb:3:in `require': no such file to load -- mysql (LoadError)
[Fri Aug 31 23:47:22 2012] [error] [client 127.0.0.1] \tfrom /Library/WebServer/CGI-Executables/test.rb:3
[Fri Aug 31 23:47:22 2012] [error] [client 127.0.0.1] Premature end of script headers: test.rb

My export paths in ~/.bashrc:

export DYLD_LIBRARY_PATH="/usr/local/mysql/lib"
export PATH="$PATH:/usr/local/mysql/bin"
export PS1="$ "

If this is any help, running gem env | grep 'RUBY EXECUTABLE'

RUBY EXECUTABLE: /Users/robertcox/.rvm/rubies/ruby-1.9.2-p318/bin/ruby

Any help appreciated

1
Just to be sure: You use ruby for pure cgi scripting, not in connection with the rails framework? - Kai Mattern
Have a look here, if that helps you out. You are probably just not including enough. stackoverflow.com/questions/5664553/… - Kai Mattern

1 Answers

0
votes

Maybe you need update gem install mysql2