Hey,
Do you want to invoke the sql using ruby code or ruby on rails…
If its just ruby then you u can go a head like this:
require ‘mysql’
mysql = Mysql.init()
mysql.connect(‘localhost’,‘USERNAME’,‘PASSWORD’)
mysql.select_db(’ DATABASE NAME’)
and proceed with the rest of the operations as required .
If its in Ruby on rails then you can configure your database.yml file
Hey,
Do you want to invoke the sql using ruby code or ruby on rails…
If its just ruby then you u can go a head like this:
require ‘mysql’
mysql = Mysql.init()
mysql.connect(‘localhost’,‘USERNAME’,‘PASSWORD’)
mysql.select_db(’ DATABASE NAME’)
and proceed with the rest of the operations as required .
If its in Ruby on rails then you can configure your database.yml file
The code what I wrote above helps u to connect to the sql server by
modifing
it a lil
require ‘mysql’
mysql = Mysql.init()
mysql.connect(‘localhost’,‘USERNAME’,‘PASSWORD’)
mysql.select_db(’ DATABASE NAME’)
result = []
result= mysql.query(“SELECT name FROM users;”)
result.each do |x|
puts x.name
end
from the above when u run ur ruby file u can see the result as list of
users
in the data base table called users .
name is the column in the users table.
hopefully this should work
You can alwyas change the database type from
mysql/postgresql/sqlite3/sql by
modifing in the correct place form the above code
cheers,
kranthi.
=begin
OS : Windows here
Ruby : 1.8.6
DB :Mysql
Gem :> gem install mysql
=end
require “mysql” #require mysql gem
connection = Mysql.connect(“localhost”, “root”, “”, “cdcol”) #localhost = hostname #root = username of mysql DB
#“”=password of mysql DB #cdcol = DB name
output = connection.query(“SELECT * FROM cds;”) #cds = table name
output.each do |x|
puts x.inspect
end
Use debugging compilers.
~ - The Elements of Programming Style (Kernighan & Plaugher)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
kranthi reddy wrote:
| The code what I wrote above helps u to connect to the sql server by
modifing
| it a lil
| require ‘mysql’
| mysql = Mysql.init()
| mysql.connect(‘localhost’,‘USERNAME’,‘PASSWORD’)
| mysql.select_db(’ DATABASE NAME’)
| result = []
| result= mysql.query(“SELECT name FROM users;”)
| result.each do |x|
| puts x.name
| end
~ I’m looking for something that can deliver a 50-pound payload of
snow
~ on a small feminine target. Can you suggest something? Hello…?
~ — Calvin
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org