这边都只是个大概,具体的要自己去看文档了.
1 连接SQLite:
require 'sqlite' db = SQLite::Database.new("library.db") db.execute("select title,author from books") do |row| p row end db.close
2连接mysql:
require 'mysql' m = Mysql.new("localhost","name","password","maillist") r = m.query("SELECT * FROM people ORDER BY name") r.each_hash do |f| print "#{f['name']} - #{f['email']}" end
3连接到PostgreSQL:
require 'postgres' conn = PGconn.connect("",5432, "", "", "testdb") conn.exec("create table rtest ( number integer default 0 );") conn.exec("insert into rtest values ( 99 )") res = conn.query("select * from rtest") # res id [["99"]]
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索sqlite
, mysql
, select
, require
, name
conn
ruby 连接数据库、ruby on rails 数据库、ruby 数据库、ruby 数据库操作、ruby数据库根据id找值,以便于您获取更多的相关知识。
时间: 2024-11-05 04:48:35