Ruby environment structures,
1, upload the ruby source package, source code download address
http://www.ruby-lang.org/en/downloads/
2, the configuration and compile the source code
./configure
Make
Make install
3, install openssl, as the source is not available, the default gem to configure HTTPS gem source need to first install openssl,
Yum install openssl
Yum install libssl - dev
Enter the ruby source directory/ext/openssl
Run:
Ruby extconfig. Rb
Make
Make install
4, install gzib,
CD rubyum install libssl - devel
Yum install libssl - devel
Enter the ruby source directory/ext/zlib
Make
Make install install directory/ext/zlib
5, the gem configuration
Gem sources - remove https://rubygems.org/
Gem sources - add https://gems.ruby-china.org/- remove https://rubygems.org/
Gem sources -l
* * * * * * CURRENT SOURCES
https://gems.ruby-china.org
6, install the unixodbc and unixodbc - devel
7, install DBD - odbc
The gem install DBD - odbc
8, install dbi
The gem install dbi
9, install ruby - odbc
The gem install ruby - odbc
10, 8 todbc configuration
11, the test code
#! The/usr/bin/ruby - w
The require "DBD/ODBC
"
The begin
# connect to MySQL server
DBH=class: : DBI. Connect (" class: : DBI: ODBC: gbase8t, "
"Informix", "informix")
DBH. Do (DROP TABLE IF the EXISTS "the EMPLOYEE")
DBH. Do (" CREATE TABLE EMPLOYEE (
The FIRST_NAME CHAR (20) NOT NULL,
LAST_NAME CHAR (20),
The AGE INT,
SEX CHAR (1),
INCOME INT)
")Puts "Table created"
DBH. Do (" INSERT INTO the EMPLOYEE (FIRST_NAME,
LAST_NAME,
AGE,
SEX,
INCOME)
VALUES (' Mac ', 'Mohan, 20,' M ', 2000) ")
Puts "Record has had created"
MIT
dbh.comSTH=DBH. Prepare (" SELECT * FROM the EMPLOYEE ")
STH. The execute ()
STH. Fetch do | row |
Printf ", First Name: % s Last Name: % s \ n ", the row [0], row [1]
Printf "Age: % d, Sex: % s \ n", the row [2], the row [3]
Printf "Salary: % d \ n \ n", the row [4]
End
STH. Finish
Rescue class: : DBI: : DatabaseError=& gt; E
Puts "An error occurred"
Puts "Error code: # {e.e rr}"
Puts "Error message: # {e.e RRSTR}"
DBH. Rollback
Ensure
# disconnect with the server connection
DBH. Disconnect the if DBH
End
12, execute code
Ruby test. Rb