# Output to mysql db

**URL:** <https://www.ruby-forum.com/t/output-to-mysql-db/82129>\
**Category:** Ruby\
**Created:** [January 17, 2007, 7:15pm UTC](https://www.ruby-forum.com/t/output-to-mysql-db/82129 "2007-01-17T19:15:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 17, 2007, 7:15pm UTC](https://www.ruby-forum.com/t/output-to-mysql-db/82129/1 "2007-01-17T19:15:53Z")

</div>

Hello,

Very new to Ruby and I’m curious if this is possible…

I have the following code which is returning a chunk of html that I  
want.

Right now, all it does is print to the screen. Is it possible to have  
the outputted chunk of html placed in a mysql db record? If so, can  
anyone recommend some starting resources or examples.

Thanks!

#!/usr/bin/env ruby

require ‘hpricot’  
require ‘open-uri’

doc = Hpricot(open(“some\_url”))

doc.search(‘dir’).each do | element |  
puts “#{element.inner\_html}”  
end

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 17, 2007, 7:36pm UTC](https://www.ruby-forum.com/t/output-to-mysql-db/82129/2 "2007-01-17T19:36:26Z")

</div>

removed\_email\_address@domain.invalid wrote:

> Hello,
> 
> Very new to Ruby and I’m curious if this is possible…
> 
> I have the following code which is returning a chunk of html that I  
> want.
> 
> Right now, all it does is print to the screen. Is it possible to have  
> the outputted chunk of html placed in a mysql db record? If so, can  
> anyone recommend some starting resources or examples.

Try ActiveRecord it’s part of Ruby on Rails :  
[http://rubyonrails.org/api/classes/ActiveRecord/Base.html](http://rubyonrails.org/api/classes/ActiveRecord/Base.html)

There’s some good examples in the Ruby Cookbook:  
[http://www.crummy.com/writing/RubyCookbook/](http://www.crummy.com/writing/RubyCookbook/)

Chris
