diff --git a/manual/codes/Basic Components - DB - Chaining listeners.php b/manual/codes/Basic Components - DB - Chaining listeners.php index f3925ffec..3f3d7de5a 100644 --- a/manual/codes/Basic Components - DB - Chaining listeners.php +++ b/manual/codes/Basic Components - DB - Chaining listeners.php @@ -2,12 +2,12 @@ // using PDO dsn for connecting sqlite memory table -$dbh = Doctrine_DB::getConnection('sqlite::memory:'); +$dbh = Doctrine_Db::getConnection('sqlite::memory:'); -class Counter extends Doctrine_DB_EventListener { +class Counter extends Doctrine_Db_EventListener { private $queries = 0; - public function onQuery(Doctrine_DB $dbh, $query, $params) { + public function onQuery(Doctrine_Db_Event $event) { $this->queries++; } public function count() { diff --git a/manual/codes/Basic Components - DB - Connecting to a database.php b/manual/codes/Basic Components - DB - Connecting to a database.php index d8af8dde3..d3f5a12fa 100644 --- a/manual/codes/Basic Components - DB - Connecting to a database.php +++ b/manual/codes/Basic Components - DB - Connecting to a database.php @@ -1,11 +1 @@ - diff --git a/manual/codes/Basic Components - DB - Introduction.php b/manual/codes/Basic Components - DB - Introduction.php new file mode 100644 index 000000000..e69de29bb diff --git a/manual/codes/Basic Components - DB - Using event listeners.php b/manual/codes/Basic Components - DB - Using event listeners.php index a2a2feb2e..43ef6a141 100644 --- a/manual/codes/Basic Components - DB - Using event listeners.php +++ b/manual/codes/Basic Components - DB - Using event listeners.php @@ -2,14 +2,14 @@ // using PDO dsn for connecting sqlite memory table -$dbh = Doctrine_DB::getConnection('sqlite::memory:'); +$dbh = Doctrine_Db::getConnection('sqlite::memory:'); -class MyLogger extends Doctrine_DB_EventListener { - public function onPreQuery(Doctrine_DB $dbh, $query, $params) { +class MyLogger extends Doctrine_Db_EventListener { + public function onPreQuery(Doctrine_Db_Event $event) { print "database is going to be queried!"; } - public function onQuery(Doctrine_DB $dbh, $query, $params) { - print "executed: $query"; + public function onQuery(Doctrine_Db_Event $event) { + print "executed: " . $event->getQuery(); } } diff --git a/manual/docs/Basic Components - DB - Chaining listeners.php b/manual/docs/Basic Components - DB - Chaining listeners.php new file mode 100644 index 000000000..af3cfa7b5 --- /dev/null +++ b/manual/docs/Basic Components - DB - Chaining listeners.php @@ -0,0 +1,7 @@ +Doctrine_Db supports event listener chaining. It means multiple listeners can be attached for +listening the events of a single instance of Doctrine_Db. +

+For example you might want to add different aspects to your Doctrine_Db instance on-demand. These aspects may include +caching, query profiling etc. +

+ diff --git a/manual/docs/Basic Components - DB - Connecting to a database.php b/manual/docs/Basic Components - DB - Connecting to a database.php index b56dabbf8..7f160addf 100644 --- a/manual/docs/Basic Components - DB - Connecting to a database.php +++ b/manual/docs/Basic Components - DB - Connecting to a database.php @@ -1,14 +1,56 @@ + +Doctrine_Db allows both PEAR-like DSN (data source name) as well as PDO like DSN as constructor parameters. +

+Getting an instance of Doctrine_Db using PEAR-like DSN: +

"; +renderCode($str); +?> +

+Getting an instance of Doctrine_Db using PDO-like DSN (PDO mysql driver): +

+"; +renderCode($str); +?> +

+Getting an instance of Doctrine_Db using PDO-like DSN (PDO sqlite with memory tables): +

+"; +renderCode($str); +?> +

+ +Handling connection errors: + +query('SELECT * FROM foo') as \$row) { + print_r(\$row); + } + \$dbh = null; +} catch (PDOException \$e) { + print 'Error!: ' . \$e->getMessage() . '
'; + die(); +} +?>"; +renderCode($str); ?> diff --git a/manual/docs/Basic Components - DB - Introduction.php b/manual/docs/Basic Components - DB - Introduction.php index 27351d0a4..a1b30849f 100644 --- a/manual/docs/Basic Components - DB - Introduction.php +++ b/manual/docs/Basic Components - DB - Introduction.php @@ -1,10 +1,10 @@ -Doctrine_DB is a wrapper for PDO database object. Why should you consider using Doctrine_DB instead of PDO? +Doctrine_Db is a wrapper for PDO database object. Why should you consider using Doctrine_Db instead of PDO?

1. It provides efficient eventlistener architecture, hence its easy to add new aspects to existing methods like on-demand-caching

-2. Doctrine_DB lazy-connects database. Creating an instance of Doctrine_DB doesn't directly connect database, hence -Doctrine_DB fits perfectly for application using for example page caching. +2. Doctrine_Db lazy-connects database. Creating an instance of Doctrine_Db doesn't directly connect database, hence +Doctrine_Db fits perfectly for application using for example page caching.

-3. It has many short cuts for commonly used fetching methods like Doctrine_DB::fetchOne(). +3. It has many short cuts for commonly used fetching methods like Doctrine_Db::fetchOne().

4. Supports PEAR-like data source names as well as PDO data source names. diff --git a/manual/docs/Basic Components - DB - Using event listeners.php b/manual/docs/Basic Components - DB - Using event listeners.php new file mode 100644 index 000000000..0a1cd5b26 --- /dev/null +++ b/manual/docs/Basic Components - DB - Using event listeners.php @@ -0,0 +1,39 @@ + +Doctrine_Db has a pluggable event listener architecture. It provides before and after +listeners for all relevant methods. Every listener method takes one parameter: a Doctrine_Db_Event object, which +holds info about the occurred event. +

+Every listener object must either implement the Doctrine_Db_EventListener_Interface or Doctrine_Overloadable interface. +Using Doctrine_Overloadable interface +only requires you to implement __call() which is then used for listening all the events.

+"; +renderCode($str); +?> +

+For convience +you may want to make your listener class extend Doctrine_Db_EventListener which has empty listener methods, hence allowing you not to define +all the listener methods by hand. The following listener, 'MyLogger', is used for listening only onPreQuery and onQuery methods.

+getQuery(); + } +} +?>"; +renderCode($str); +?> +

+Now the next thing we need to do is bind the eventlistener objects to our database handler. +

diff --git a/manual/documentation.php b/manual/documentation.php index eb7a7b049..e1f8c7fd0 100644 --- a/manual/documentation.php +++ b/manual/documentation.php @@ -59,15 +59,17 @@ function render_block($name) { renderCode($c); } } + function renderCode($c = null) { + global $h; if( ! empty($c)) { - $h = new PHP_Highlight; + $h->loadString($c); print ""; print ""; print "
"; - print $h->toHtml(); + $h->toHtml(); print "
"; } @@ -197,7 +199,7 @@ $menu = array("Getting started" => "Using SQL", "Adding components", "Method overloading"), - "DB" => array( + "Db" => array( "Introduction", "Connecting to a database", "Using event listeners",