简单的远程ODBC数据库连接与ruby [英] simple remote ODBC database connection with ruby

查看:139
本文介绍了简单的远程ODBC数据库连接与ruby的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试连接到远程数据库。我不能让它工作。

I am attempting to make a simple connection to a remote database. I can not seem to get it to work.

remote_db = DBI.connect('DBI:ODBC:remote-host','user','password')
remote_db.table { |table| pp table }

任何帮助将非常感谢。

Any help would be greatly appreciated.

推荐答案

我认为你正在寻找的是Ruby DBI。

http://ruby-dbi.rubyforge.org/

以下是使用DBI进行ODBC连接的示例:

Here is an example of using DBI for ODBC connectivity:

# Require in the DBI files<br />
require 'DBI'

# create an ODBC connection instance<br />
dbi_conn = DBI.connect('DBI:ODBC:datasource','your_username','your_password')

# query tables available  <br />
dbi_conn.tables

# returns an array with the results from a table TABLE:<br />
array_out = dbi_conn.select_all('SELECT * FROM TABLE')

深度信息:

http://www.kitebird.com /articles/ruby-dbi.html

或者,您也可以使用ruby-odbc:

http://odbc-rails.rubyforge.org/

Or, alternatively, you can use ruby-odbc:
http://odbc-rails.rubyforge.org/

这篇关于简单的远程ODBC数据库连接与ruby的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆