From ac34e4bfc00a8d23830f86fd19997384fd0a5fcb Mon Sep 17 00:00:00 2001 From: zYne Date: Thu, 14 Dec 2006 13:27:10 +0000 Subject: [PATCH] added connection management docs --- ...nagement - Lazy-connecting to database.php | 21 ++++++ ...tion management - Managing connections.php | 71 +++++++++++++++++++ ... management - Opening a new connection.php | 40 +++++++++++ ...Doctrine Query Language) - FROM clause.php | 2 +- 4 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 manual/docs/Connection management - Lazy-connecting to database.php create mode 100644 manual/docs/Connection management - Managing connections.php create mode 100644 manual/docs/Connection management - Opening a new connection.php diff --git a/manual/docs/Connection management - Lazy-connecting to database.php b/manual/docs/Connection management - Lazy-connecting to database.php new file mode 100644 index 000000000..44646ea6b --- /dev/null +++ b/manual/docs/Connection management - Lazy-connecting to database.php @@ -0,0 +1,21 @@ + +Lazy-connecting to database is handled via Doctrine_Db wrapper. When using Doctrine_Db instead of PDO / Doctrine_Adapter, lazy-connecting +to database is being performed (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. +

+query('FROM User u'); + +?>"); +?> diff --git a/manual/docs/Connection management - Managing connections.php b/manual/docs/Connection management - Managing connections.php new file mode 100644 index 000000000..4279c5c3b --- /dev/null +++ b/manual/docs/Connection management - Managing connections.php @@ -0,0 +1,71 @@ + +From the start Doctrine has been designed to work with multiple connections. Unless separately specified Doctrine always uses the current connection +for executing the queries. The following example uses openConnection() second argument as an optional +connection alias. +

+openConnection(new PDO('dsn','username','password'), 'connection 1'); +?> +"); +?> +

+For convenience Doctrine_Manager provides static method connection() which opens new connection when arguments are given to it and returns the current +connection when no arguments have been speficied. +

+ +"); +?> + + +

+The current connection is the lastly opened connection. +

+openConnection(new PDO('dsn2','username2','password2'), 'connection 2'); + +\$manager->getCurrentConnection(); // \$conn2 +?>"); +?> +

+You can change the current connection by calling setCurrentConnection(). +

+setCurrentConnection('connection 1'); + +\$manager->getCurrentConnection(); // \$conn +?> +"); +?> +

+You can iterate over the opened connection by simple passing the manager object to foreach clause. This is possible since Doctrine_Manager implements +special IteratorAggregate interface. +

+"); +?> diff --git a/manual/docs/Connection management - Opening a new connection.php b/manual/docs/Connection management - Opening a new connection.php new file mode 100644 index 000000000..0b6dffa9d --- /dev/null +++ b/manual/docs/Connection management - Opening a new connection.php @@ -0,0 +1,40 @@ + +Opening a new database connection in Doctrine is very easy. If you wish to use PDO (www.php.net/PDO) you can just initalize a new PDO object: +

+getMessage(); +} +?>"); +?> +

+If your database extension isn't supported by PDO you can use special Doctrine_Adapter class (if availible). The following example uses db2 adapter: +

+getMessage(); +} +?>"); +?> +

+The next step is opening a new Doctrine_Connection. +

+"); +?> diff --git a/manual/docs/DQL (Doctrine Query Language) - FROM clause.php b/manual/docs/DQL (Doctrine Query Language) - FROM clause.php index 53c91ef2d..084b837a6 100644 --- a/manual/docs/DQL (Doctrine Query Language) - FROM clause.php +++ b/manual/docs/DQL (Doctrine Query Language) - FROM clause.php @@ -21,7 +21,7 @@ SELECT u.*, p.* FROM User u, u.Phonenumber p -
  • INNER JOIN produces a Cartesian product between two specified components (that is, each and every record in the first component is joined to each and every record in the second component). +
  • INNER JOIN produces an intersection between two specified components (that is, each and every record in the first component is joined to each and every record in the second component). So basically INNER JOIN can be used when you want to efficiently fetch for example all users which have one or more phonenumbers.