How to connect to sql host using dbi

Hello,

I’m trying to use dbi in place of postgres to connect to my PostgreSQL
and fetch some data. The bone of script that will do this follows
—>cut<—
#!/usr/bin/env ruby

$Id$

require 'dbi’
DBI.connect(‘DBI:Pg:dbname=testdb;host=sql’, nil, nil) do |dbh|
puts "selecting…"
end
—>cut<—
but I do not know how to say to dbi that the database is not on
localhost but on host sql. Diging arround and on the net I didn’t
found any usefull help.

···


Radek Hnilica

No matter how far down the wrong road you’ve gone, turn back.
Turkish proverb

I'm trying to use dbi in place of postgres to connect to my PostgreSQL
and fetch some data. The bone of script that will do this follows
--->cut<---
#!/usr/bin/env ruby
# $Id$
require 'dbi'
DBI.connect('DBI:Pg:dbname=testdb;host=sql', nil, nil) do |dbh|
    puts "selecting..."
end
--->cut<---
but I do not know how to say to dbi that the database is not on
localhost but on host sql. Diging arround and on the net I didn't
found any usefull help.

You were very close:

#!/usr/bin/env ruby
# $Id$
require 'dbi'
DBI.connect('DBI:Pg:testdb;sql', nil, nil) do |dbh|
    puts "selecting..."
end

-sc

···

--
Sean Chittenden

this doesn’t work to.

After some experimenting I come with this code which works. It means
it doesn’t fail. The data fetch will be tested in near future.

—>code<—
#!/usr/bin/env ruby

$Id: list_records.rb,v 1.1 2002/07/09 14:48:41 radek Exp $

require ‘dbi’

DBI.connect(‘DBI:Pg:dbname=testdb;host=sql’, ‘radek’) do |dbh|
puts "selecting…"
end
—>end code<—

···

In article 20020709185451.GE62567@ninja1.internal, Sean Chittenden wrote:

You were very close:

#!/usr/bin/env ruby

$Id$

require 'dbi’
DBI.connect(‘DBI:Pg:testdb;sql’, nil, nil) do |dbh|
puts "selecting…"
end


Radek Hnilica

No matter how far down the wrong road you’ve gone, turn back.
Turkish proverb

Ok, thanks, it’s now written in my workbook.

···

In article 20020710090421.GB3519@rz.uni-karlsruhe.de, Michael Neumann wrote:

This is correct. Following options are available:

  • dbname (or database)
  • host
  • port
  • options
  • tty


Radek Hnilica

No matter how far down the wrong road you’ve gone, turn back.
Turkish proverb

This is correct. Following options are available:

  • dbname (or database)
  • host
  • port
  • options
  • tty

Regards,

Michael

···

On Wed, Jul 10, 2002 at 05:48:48PM +0900, Radek Hnilica wrote:

In article 20020709185451.GE62567@ninja1.internal, Sean Chittenden wrote:

You were very close:

#!/usr/bin/env ruby

$Id$

require 'dbi’
DBI.connect(‘DBI:Pg:testdb;sql’, nil, nil) do |dbh|
puts "selecting…"
end

this doesn’t work to.

After some experimenting I come with this code which works. It means
it doesn’t fail. The data fetch will be tested in near future.

—>code<—
#!/usr/bin/env ruby

$Id: list_records.rb,v 1.1 2002/07/09 14:48:41 radek Exp $

require ‘dbi’

DBI.connect(‘DBI:Pg:dbname=testdb;host=sql’, ‘radek’) do |dbh|
puts "selecting…"
end
—>end code<—