Ruby Direct underlying connection database

Source: Internet
Author: User

Class Mysqltest #Code here require "MySQL" Def testmysql dbc=mysql.real_connect (' localhost ', ' root ', ' 123 ', ' Ivic_porta L ') res=dbc.query (' select * from Virtual_machines ') puts "Test Mysql ...." While Row=res.fetch_row do puts "# {row[0]} "end End Def createtable dbc=mysql.real_connect (' localhost ', ' root ', ' 123 ', ' ivic_portal ') res = Dbc.quer Y ("Select Id,hostname,internet_tx,internet_rx,traffic_tx,traffic_rx from Virtual_machines") puts "===select Data===/ n "While row = Res.fetch_row do printf ("%s,%s,%s,%s,%s,%s\n ", row[0],row[1],row[2],row[3],row[4],row[5]) en  D puts "==================/n" puts "Server version:" + dbc.get_server_info Rescue Mysql::error = e puts "Error code: #{e.errno}" puts "error message: #{e.error}" puts "error SQLSTATE: #{e.sqlstate}" if e.respond_to? ("SQLState") ensure puts "Close Connection ..." Dbc.close if DBC end def Insertinto Dbc=mysql.real_co Nnect (' localhost ', ' root ', ' 1(' ivic_portal ') res = dbc.query ("Select Id,hostname,internet_tx,internet_rx,traffic_tx,traffic_rx from Virtual_      Machines ") while row = Res.fetch_row do id = row[0] a = rand (+) B = rand (+) c = rand (1000)      D = rand (puts) a,b,c,d printf ("%s,%s,%s,%s,%s,%s\n", row[0],row[1],row[2],row[3],row[4],row[5]) Dbc.query ("Update virtual_machines set internet_tx=internet_tx+#{a} where id = #{id}") Dbc.query ("Update virtual_ma Chines set INTERNET_RX=INTERNET_RX+#{B} where id = #{id} ") Dbc.query (" Update virtual_machines set traffic_tx=traffic    _TX+#{C} WHERE id = #{id} ") Dbc.query (" Update virtual_machines set traffic_rx=traffic_rx+#{d} where id = #{id} ") End Rescue Mysql::error = e puts "error code: #{e.errno}" puts "error message: #{e.error}" puts "Er Ror SQLSTATE: #{e.sqlstate} "if e.respond_to? ("SQLState") ensure puts "Close Connection ..." dbc.close if DBC end while true do (Mysqltest.new). Insertinto (mysqltest.new). CreateTable Sleep (5) EndEnd 

  

Ruby Direct underlying connection database

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.