This is documentation for Kohana v2.3.x.

Table of Contents
StatusDraft
TodoProof read

<< Back to Database Main Page

Connecting to a database

Connecting with the database library is very simple. Most of the time, you never need to think about it! Kohana has the following features to make your connection life much easier:

Lazy connection

Kohana will not connect to your database until it needs to perform a query or get some table metadata. This is useful when you employ query or page caching, so you don't use a connection when it isn't needed.

Connection caching

Kohana uses the default behaviors in native php database methods to cache the database connection when using the same database group with multiple database objects.

Multiple database support

Kohana has the ability to connect to multiple databases at once by simply having multiple config groups, and creating new objects with them.

$db1 = new Database('db1');
$db2 = new Database('db2');

where db1 and db2 would be config groups in your database configuration.

Continue to the next section: Querying a database >>