An active record abstracts the concept of a database connection and helps the application to handle the details of the underlying database links, in lieu of the active record using a generic invocation to delegate the details to a set of database adapters.
You can use the Establish_connection () method to make a connection, the following example creates a MySQL database connection, the name of the database is Railsdb, The server's host name is dbserver.com, the user name is Railsuser, and the password is RAILSPW.
Activerecord::base.establish_connection (
: Adapter => "MySQL"
: Host => "dbserver.com",
:d atabase => "Railsdb",
: Username => "Railsuser",
:p assword => "RAILSPW"
)
The Active record supports Db2,mysql,oracle,postgres,sqlserver and Sqllite, each of which has a small difference in the parameters of the link, and the following table lists the commonly used parameters:
Note that the Oracle adapter name is OCI.
The database connection is associated with the model class, and each class inherits the link from the parent class, activerecord::base as the parent of all active record classes, setting up the database connection here to link all the active records classes, and of course, if necessary, You can also make a replication (override) Link configuration.