Ruby/DBI是一个跟Perl/DBI类似的统一数据库访问接口,支持各种流行的数据库。
下面是一段使用了Ruby/DBI的代码:
#!/usr/bi/ruby-w#simple.rb-simpleMySQLscriptusigRubyDBImodulerequire"dbi"begi#coecttotheMySQLserverdbh=DBI.coect("DBI:Mysql:test:localhost","testuser","testpass")#getserverversiostrigaddisplayitrow=dbh.select_oe("SELECTVERSION()")puts"Serverversio:"+row[0]rescueDBI::DatabaseError=>eputs"Aerroroccurred"puts"Errorcode:#{e.err}"puts"Errormessage:#{e.errstr}"esure#discoectfromserverdbh.discoectifdbhed
评论