15 lines
727 B
Plaintext
15 lines
727 B
Plaintext
Lazy-connecting to database can save a lot of resources. There might be many pages where you don't need an actual database connection, hence its always recommended to use lazy-connecting (that means Doctrine will only connect to database when needed).
|
|
|
|
This feature can be very useful when using for example page caching, hence not actually needing a database connection on every request. Remember connecting to database is an expensive operation.
|
|
|
|
<code type="php">
|
|
$dsn = 'mysql://username:password@localhost/test';
|
|
|
|
// initalize a new Doctrine_Connection
|
|
$conn = Doctrine_Manager::connection($dsn);
|
|
// !! no actual database connection yet !!
|
|
|
|
// connects database and performs a query
|
|
$conn->query('FROM User u');
|
|
</code>
|