Ruby +Mysql

Connecting, retriving data from MYSQL database:

Code

require ‘mysql’

db = Mysql::new(“localhost”, “root”, “”, “new_development”)
sql = “SELECT url FROM sites;”
x= db.query(sql)
x.each do |record|
puts record
end

Note:

root – SQL  db user name

“” – Password for root access

new_development – DB Name

url –  Field Name

sites – Table Name

Output:

From sites table –> url field –>

http://yahoomail.com
http://70.85.16.159/
google.com
yahoo.com
google.com

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s