# How can I connect ruby with postgreSQL

**URL:** <https://www.ruby-forum.com/t/how-can-i-connect-ruby-with-postgresql/114974>\
**Category:** Ruby\
**Created:** [September 19, 2007, 12:10pm UTC](https://www.ruby-forum.com/t/how-can-i-connect-ruby-with-postgresql/114974 "2007-09-19T12:10:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vellingiri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5fc32e/32.png) [@vellingiri](https://www.ruby-forum.com/u/vellingiri)\
**Post date:** [September 19, 2007, 12:10pm UTC](https://www.ruby-forum.com/t/how-can-i-connect-ruby-with-postgresql/114974/1 "2007-09-19T12:10:44Z")

</div>

Dear Friends,  
how can I connect ruby with postgreSQL.  
Please give some procedure.  
how can I install the proper packages and what are the configurations I  
am going to made.  
what are the steps I have to follow that’s what all I want.

by  
Vellingiri

---

<div class="post-metadata">

**Author:** ![vellingiri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5fc32e/32.png) [@vellingiri](https://www.ruby-forum.com/u/vellingiri)\
**Post date:** [September 20, 2007, 7:55am UTC](https://www.ruby-forum.com/t/how-can-i-connect-ruby-with-postgresql/114974/2 "2007-09-20T07:55:03Z")

</div>

Vellingiri A. wrote:

> Dear Friends,  
> how can I connect ruby with postgreSQL.  
> Please give some procedure.  
> how can I install the proper packages and what are the configurations I  
> am going to made.  
> what are the steps I have to follow that’s what all I want.
> 
> by  
> Vellingiri

Google for “ruby DBI”

Examples:  
dbh = DBI.connect(‘DBI:Pg:mydb’, ‘user’, ‘pwd’)  
rs = dbh.select\_all(“select \* from table where id = ‘#{someID}’”)  
dbh.do(“update table set num=#{n} where id=’#{someID}’”)

sth = dbh.prepare(“INSERT INTO table (v1,v2,v3,v4) VALUES(?, ?, ?,  
?)”)  
sth.execute(‘a’, ‘b’, ‘c’, d)

by  
TheR

---

<div class="post-metadata">

**Author:** ![vellingiri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5fc32e/32.png) [@vellingiri](https://www.ruby-forum.com/u/vellingiri)\
**Post date:** [September 20, 2007, 9:13am UTC](https://www.ruby-forum.com/t/how-can-i-connect-ruby-with-postgresql/114974/3 "2007-09-20T09:13:36Z")

</div>

Damjan R. wrote:

> Vellingiri A. wrote:
> 
> > Dear Friends,  
> > how can I connect ruby with postgreSQL.  
> > Please give some procedure.  
> > how can I install the proper packages and what are the configurations I  
> > am going to made.  
> > what are the steps I have to follow that’s what all I want.
> > 
> > by  
> > Vellingiri
> 
> Google for “ruby DBI”
> 
> Examples:  
> dbh = DBI.connect(‘DBI:Pg:mydb’, ‘user’, ‘pwd’)  
> rs = dbh.select\_all(“select \* from table where id = ‘#{someID}’”)  
> dbh.do(“update table set num=#{n} where id=’#{someID}’”)
> 
> sth = dbh.prepare(“INSERT INTO table (v1,v2,v3,v4) VALUES(?, ?, ?,  
> ?)”)  
> sth.execute(‘a’, ‘b’, ‘c’, d)
> 
> by  
> TheR

Ok Friends,  
Whatever you told and you gave one link know that link was very  
useful for me.  
But I am having only postgreSQl,Using that how can I able to install.  
And also i have got lot of information form that site.  
But ,I was unable to findout the proper solution for this.  
Please explain clearly.

by  
Vellingiri.

---

<div class="post-metadata">

**Author:** ![vellingiri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5fc32e/32.png) [@vellingiri](https://www.ruby-forum.com/u/vellingiri)\
**Post date:** [September 20, 2007, 11:13am UTC](https://www.ruby-forum.com/t/how-can-i-connect-ruby-with-postgresql/114974/4 "2007-09-20T11:13:37Z")

</div>

Vellingiri A. wrote:

> > > Vellingiri
> 
> by  
> Vellingiri.  
> not clearly:  
> RFTM

clearly  
read documentation on ruby-postgres  
read pickaxe,  
use google

this question(or similar like how to use mysql, or Active Record outside  
rails) was answered already many times, on this mailing list, on blogs,  
in documentation there are examples, noone here will write software for  
you(well i can my hourly rate is only $10)
