Using Ruby/MySQL
http://sitekreator.com/satishtalim/toc.html
Using Ruby/MySQL
MySQL support in Ruby was made possible by Tomita Masahiro. He has developed a pure Ruby binding called Ruby/MySQL.
We need to install the same on our PC and the installation (you need to be connected to the internet and it takes some time) is as shown below:
C:\>gem install mysql Bulk updating Gem source index for: http://gems.rubyforge.org Select which gem to install for your platform (i386-mswin32) 1. mysql 2.7.1 (mswin32) 2. mysql 2.7 (ruby) 3. mysql 2.6 (ruby) 4. mysql 2.5.1 (ruby) 5. Cancel installation > 1 Successfully installed mysql-2.7.1-mswin32 Installing ri documentation for mysql-2.7.1-mswin32... Installing RDoc documentation for mysql-2.7.1-mswin32... C:\>
This installs mysql-2.7.1-mswin32 driver which is faster and supports MySQL 4.1 and later. The documentation for this driver is here.
I will assume that you've already installed mySQL 4.1 or above on your PC and that you have it running and are familiar with the basics.
Now, run the mysql client program from the command line, as:
You should get the mysql prompt. Next, create a database ruby as:
mysql> create database ruby; Query OK, 1 row affected (0.02 sec)
mysql> use ruby; create table student (id VARCHAR(2), name VARCHAR(20), rank VARCHAR(2));
require 'mysql' con = Mysql.new('localhost', '', '', 'ruby') rs = con.query('select * from student') rs.each_hash {|h| puts h['name']} con.close |