*Dear All:* I need your help on following points. 1. Can I connect Ruby with MySQL in XAMPP server? 2. Could someone tell me that how to connect MySQL with Ruby? I have XAMPP server installed and want to connect with ruby. I am using Ruby1.8.7. I tried following code: require ''rubygems'' require ''mysql'' begin # connect to the MySQL server dbh = Mysql.connect("localhost", "root", "root", "status_publish") puts dbh # get server version string and display it puts "Server version: " + dbh.get_server_info rescue Mysql::Error => e puts "Error code: #{e.errno}" puts "Error message: #{e.error}" puts "Error SQLSTATE: #{e.sqlstate}" if e.respond_to?("sqlstate") ensure # disconnect from server dbh.close if dbh end *OUTPUT: *C:/xampp/htdocs/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'': no such file to load -- mysql (LoadError) from C:/xampp/htdocs/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'' from ruby_dbconnect.rb:4 Please help. Thanks in advanced. -- Thanks and Regards, Amit -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en.
Hi, I got the solution. I just ran a command: *gem install mysql* and the error went away. Now I am strugling with- how to select data from the mysql table. I tried so many ways but no luck. Could somebody add focus on this? Thanks in advance. Thanks, Amit On Wed, Aug 24, 2011 at 8:44 PM, Amit Bobade <amit.srpce-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> *Dear All:* > > I need your help on following points. > > 1. Can I connect Ruby with MySQL in XAMPP server? > > 2. Could someone tell me that how to connect MySQL with Ruby? I have XAMPP > server installed and want to connect with ruby. > > > I am using Ruby1.8.7. > > I tried following code: > > require ''rubygems'' > require ''mysql'' > > begin > # connect to the MySQL server > dbh = Mysql.connect("localhost", "root", "root", "status_publish") > puts dbh > # get server version string and display it > puts "Server version: " + dbh.get_server_info > rescue Mysql::Error => e > puts "Error code: #{e.errno}" > puts "Error message: #{e.error}" > puts "Error SQLSTATE: #{e.sqlstate}" if e.respond_to?("sqlstate") > ensure > # disconnect from server > dbh.close if dbh > end > > *OUTPUT: *C:/xampp/htdocs/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in > `gem_original_require'': no such file to load -- mysql (LoadError) > from > C:/xampp/htdocs/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in > `require'' > from ruby_dbconnect.rb:4 > > Please help. > > Thanks in advanced. > > -- > Thanks and Regards, > Amit > >-- Thanks and Regards, Amit -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en.
On 24 August 2011 16:37, Amit Bobade <amit.srpce-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I got the solution. I just ran a command: gem install mysql and the error > went away. > > Now I am strugling with- how to select data from the mysql table. I tried so > many ways but no luck.I suggest you look at the Rails Guides, start with Getting Started, obviously, and work through some Rails tutorials railstutorial.org is good and free to use online. Make sure you use Rails 3 and that any tutorials you try are for Rails 3 Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en.
On Aug 24, 2011, at 11:37 AM, Amit Bobade wrote:> Hi, > > I got the solution. I just ran a command: gem install mysql and the > error went away. > > Now I am strugling with- how to select data from the mysql table. I > tried so many ways but no luck. > > Could somebody add focus on this?You''re probably going to get more takers on the ruby-talk list, rather than rails-talk. We''re all very busy with our integrated framework, rather than trying to build a connection to a database with stone knives and bear skins. (kidding about that!) You''ve got a database handle (dbh). Before you close it in your script, use it to issue a SQL command to the server, like this: res = dbh.query("SELECT name, category FROM animal") while row = res.fetch_hash do printf "%s, %s\n", row["name"], row["category"] end This is all from here: kitebird.com/articles/ruby-mysql.html#TOC_7 Walter -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en.