Created
May 4, 2010 09:09
-
-
Save gonglexin/389165 to your computer and use it in GitHub Desktop.
Ruby:ActiveRecord连接数据库
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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