To use the database that we just created, we first need to establish a connection to it.
We are going to use Data Access Objects (DAO) to abstract our data access mechanisms. If in future we decide to use a different DBMS (e.g. PostgreSQL, Oracle) to store our blog data, we only need to change the database source name (DSN) and we can keep our PHP code intact.
To further reduce the dependency on the actual database tables, we will also use the Active Record feature which is based on PDO. Each data record will be represented as an Active Record object, which saves us from writing repetitive SQL statements.
We modify our application configuration file protected/application.xml by inserting the following lines, which tells Active Record how to connect to our newly created database:
The configuration above shows that we are adding to our application a module whose class is specified in the namespace format as System.Data.ActiveRecord.TActiveRecordConfig. Through this module, Active Record will automatically establish a DB connection by using the connection information given in ConnectionString.