新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
幾種常見Ruby連接數(shù)據(jù)庫技巧講解
我們在使用Ruby語言的時候,經(jīng)常會遇到與數(shù)據(jù)庫相關的知識。在這里我們將會學到一些常見的Ruby連接數(shù)據(jù)庫的一些技巧講解。#t#

成都創(chuàng)新互聯(lián)公司,為您提供成都網(wǎng)站建設、成都網(wǎng)站制作、網(wǎng)站營銷推廣、網(wǎng)站開發(fā)設計,對服務成都展覽展示等多個行業(yè)擁有豐富的網(wǎng)站建設及推廣經(jīng)驗。成都創(chuàng)新互聯(lián)公司網(wǎng)站建設公司成立于2013年,提供專業(yè)網(wǎng)站制作報價服務,我們深知市場的競爭激烈,認真對待每位客戶,為客戶提供賞心悅目的作品。 與客戶共同發(fā)展進步,是我們永遠的責任!
Ruby連接數(shù)據(jù)庫1 連接SQLite:
- require 'sqlite'
- db = SQLite::Database.new
("library.db") - db.execute("select title,
author from books") do |row| - p row
- end
- db.close
Ruby連接數(shù)據(jù)庫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
Ruby連接數(shù)據(jù)庫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"]]
本文題目:幾種常見Ruby連接數(shù)據(jù)庫技巧講解
瀏覽路徑:http://m.5511xx.com/article/dpsesgi.html


咨詢
建站咨詢
