Skip to content

Instantly share code, notes, and snippets.

@gonglexin
Created May 4, 2010 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gonglexin/389165 to your computer and use it in GitHub Desktop.
Save gonglexin/389165 to your computer and use it in GitHub Desktop.
Ruby:ActiveRecord连接数据库
require 'rubygems'
require 'activerecord'
# 利用 activerecord 连接数据库
ActiveRecord::Base.establish_connection(:adapter => "mysql",
:host => 'localhost',
:username => "root",
:password => "root",
#:prot => "3306",
:database => "depot_development"
#:encoding => "utf8"
)
class User < ActiveRecord::Base
end
user = User.find(4)
p user
=begin
users = User.all
users.each do |user|
p user.name
end
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment