Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Rubyʵ¼ù—Á¬½ÓMysql

°²×°»·¾³£º
OS£ºWindows XP
Ruby: Ruby1.9.1
Mysql: Mysql5.1.46 £¨username/password: root/root  port:3306£©
Ruby-Mysql Driver: mysql-2.8.1-x86-mswin32.gem
£¨×¢£ºÓÃ2.7.3°æ±¾µÄÇý¶¯ÔÚ²âÊÔʱ»á³öÏÖ require"mysql"£¬ÕÒ²»µ½Ö¸¶¨Ä£¿é ´íÎó£©
IDE£ºRubyMine2.0.1
°²×°Ruby,RubyMine,MysqlµÄÊÂÏîÔÚÕâÀï¾Í²»¶à˵ÁË£¬Ìáһϰ²×°Çý¶¯µÄ²½Öè
1£©ÔÚMysql°²×°Ä¿Â¼µÄ bin Ŀ¼Ï£¬ÕÒµ½ ibmySQL.dll £¬½«¸ÃÎļþ¸´ÖƵ½ Ruby °²×°Ä¿Â¼µÄ bin Ŀ¼ÖÐ
2£©http://rubyforge.org/frs/?group_id=1598£¬ÏÂÔØ mysql-2.8.1-x86-mswin32.gem£¬ÕâÊÇ mysql_RubyÇý¶¯³ÌÐò¡£
       ÃüÁîÐУ¬½øÈë¸ÃÎļþËùÔÚĿ¼£¬ÔËÐС¡gem install mysql-2.8.1-x86-mswin32.gem £¬°²×°³É¹¦¼´¿É¡£
     
´´½¨Ruby²âÊÔÀà
MysqlTest.rb
class MysqlTest
#Code here
require "mysql"
def testMysql
dbc=Mysql.real_connect('localhost','root','root','mysql')
res=dbc.query('select * from user')
puts "Test Mysql...."
while row=res.fetch_row do
puts "#{row[0]}"
end
end
def createTable
dbc=Mysql.real_connect('localhost','root','root','test')
dbc.query("drop table if exists cux_users")
dbc.query("create table cux_users(id int,name char(20))")
dbc.query("insert into cux_users values(1,'Tom')")
printf "Create Table........"
printf "%d rows were inserted\n",dbc.affected_rows
res = dbc.query("SELECT name from cux_users")
puts "===Select Data===\n"
while row = res.fetch_row do
printf "%s, %s\n", row[0], row[1]
end
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
(MysqlTest.new).testMysql
(MysqlTest.new).createTable
end
²âÊÔ½á¹û£º
C:\Ruby19\bin\ruby.exe -e STDOUT.sync=true;


Ïà¹ØÎĵµ£º

Install Cassandra with Ruby 1.9.1 on Windows

To get it done is not easy. I spent a whole day to figure out the various compatibility issues along the way out.
Now there still might be potential issues, but it works by my rough test.
Step 1: Install Apache Cassandra
  You may know that the Ruby gem cassandra will do it for you.
  ......

ÁùÖÖÓÃrubyµ÷ÓÃÖ´ÐÐshellÃüÁîµÄ·½·¨

ÁùÖÖÓÃrubyµ÷ÓÃÖ´ÐÐshellÃüÁîµÄ·½·¨
Åöµ½ÐèÒªµ÷ÓòÙ×÷ϵͳshellÃüÁîµÄʱºò£¬RubyΪÎÒÃÇÌṩÁËÁùÖÖÍê³ÉÈÎÎñµÄ·½·¨£º
1.Exec·½·¨:
    Kernel#exec·½·¨Í¨¹ýµ÷ÓÃÖ¸¶¨µÄÃüÁîÈ¡´úµ±Ç°½ø³Ì£º
  Àý×Ó£º
      $ irb
      >> exec 'echo " ......

Ruby ¼ò½é

    Ruby£¬Ò»ÖÖ為簡單¿ì½ÝÎï¼þ導Ïò編³Ì£¨ÃæÏò¶ÔÏó³ÌÐòÉè¼Æ£©¶ø創µÄ½Å±¾語ÑÔ£¬ÔÚ20ÊÀ¼Í90Äê´úÓÉÈÕ±¾ÈËËɱ¾Ðк루¤Þ¤Ä¤â¤È¤æ¤­¤Ò¤í£¯Yukihiro Matsumoto£©¿ª·¢£¬×ñÊØGPLЭÒéºÍRuby License¡£ËüµÄÁé¸ÐÓëÌØÐÔÀ´×ÔÓÚPerl¡¢Smalltalk¡¢Eiffel¡¢Ada ÒÔ¼° Lisp ......

rubyµÄÀàÓëÄ£¿é£¨1£©

class Point
@x = 1
@y = 2
def initialize(x,y)
@x,@y = x,y
end
end 
´úÂëÖеÄ@x£¬@yΪʵÀý±äÁ¿£¬ÊµÀý±äÁ¿Ö»¶ÔselfµÄ»·¾³Æð×÷Óã¬Òò´ËinitializeÍâÃæµÄ@x=1£¬@y=2Ö»¶ÔÀà±¾ÉíÆð×÷Ó㬶ø·½·¨ÄÚ²¿£¬µÄ@x£¬@yÊǶԶÔÏóµÄʵÀýÆð×÷Óõġ£
class Point
include Enumerable
def initialize(x ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ