#gem install mysql或者gem install ruby-mysql或gem ins dbd-mysql,拷贝
mysql安装目录中的libmySQL.dll到ruby的lib目录
#mysql 连接数据库
#~ require 'mysql'
#~ db=Mysql.connect("192.168.1.40","root","123456","op",)
#~ query=db.query('select * from t_serverinfo')
#~ query.each_
hash do |h|
#~ puts h.inspect
#~ end
#~ db.close
#DBI连接数据库
#~ require 'dbi'
#~ db=DBI.connect('DBI:Mysql:op:192.168.1.40','root','123456')
#~ db.select_all('select * from t_serverinfo') do |row|
#~ puts row.inspect
#~ end
#~ db.disconnect
#下载0.2.*
版本DBI,解压放到ruby/lib中,
#运行ruby setup.rb config;
#ruby setup.rb setup
#ruby setup.rb install
#要把解压bdi中的ado.rb文件放在如下目录,(目录没有自建)
#../ruby/lib/ruby/site_ruby/1.8/DBD/ADO/
require 'dbi'
require 'win32ole'
db=DBI.connect('DBI:ADO:Provider=SQLOLEDB.1;Data Source="192.168.100.51,1433";initial Catalog="guagua_money";User Id="sa";Password="123456"')
#~ db.do("insert into t_user_money(user_id) values(?,?)",user_id) #插入数据
query=db.prepare("select top(100) * from t_user_money")
query.execute
while row=query.fetch_hash do
puts row.inspect
end
sth.finish