1
0
mirror of synced 2024-12-15 23:56:02 +03:00
doctrine2/manual/docs/en/connection-management/lazy-connecting-to-database.txt

15 lines
727 B
Plaintext
Raw Normal View History

2007-06-20 17:17:15 +04:00
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).
2007-06-13 02:18:21 +04:00
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">
2007-06-20 17:17:15 +04:00
$dsn = 'mysql://username:password@localhost/test';
2007-06-13 02:18:21 +04:00
// initalize a new Doctrine_Connection
2007-06-20 17:17:15 +04:00
$conn = Doctrine_Manager::connection($dsn);
2007-06-13 02:18:21 +04:00
// !! no actual database connection yet !!
// connects database and performs a query
$conn->query('FROM User u');
</code>