Ruby Way Connection Database

Source: Internet
Author: User
Tags sqlite

This side is just a general, specific to see the document itself.

1 Connection SQLite:

Require ' SQLite '
db = SQLite::D atabase.new ("library.db")
db.execute ("Select Title,author from Books ") Do |row|
p row end
db.close     

2 connection MySQL:

Require ' MySQL '
m = mysql.new ("localhost", "name", "Password", "Maillist")
r = M.query ("SELECT * FROM People order by name "
R.each_hash does |f|
print" #{f[' name '}-#{f[' email '} "
end 

3 Connections to PostgreSQL:

Require ' postgres '
conn = Pgconn.connect ("", 5432, "", "", "TestDB")
conn.exec ("CREATE Table Rtest" (Numb ER integer default 0); "
Conn.exec (INSERT into rtest values (?)
res = conn.query ("SELECT * from Rtest")
# res ID [[' 99]] 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.