Right. The behavior used to be that the connection was initiated lazily, only when a query was executed. This required the user to make a "dummy" query like "SELECT 1" to force the connection, as Jude found.
In ZF 0.8 I made the getConnection() method force a connection, to give people a chance to initiate without having to run a query. But there is still value in making the connection lazily. Regards, Bill Karwin > -----Original Message----- > From: Guillaume Millet [mailto:[EMAIL PROTECTED] > Sent: Wednesday, March 21, 2007 4:02 AM > To: Zend Framework General > Subject: Re: [fw-general] Zend_Db Exception throwing? > > This is the behaviour I expected the first time I used Zend_Db. However, > when I found out that the connection is made only when necessary, I was > more willing to instanciate my $db object in my config file (so it's > only in a single place) since it doesn't connect to my database server > for pages that don't fetch data from it. > > Regards, > > Guillaume > > Doctorrock a écrit : > > > That's true Bill, but why not to put that code inside the Framework > > itself ? > > > > That way, when setting up a connection via the Factory, the Framework > > could try (itself) to connect to the database, and throw an Exception > > if it could not, instead of relying on the programmer to do so. > > > > - Julien from http://www.z-f.fr - > > > > > > 2007/3/19, Bill Karwin < [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>: > > > > FYI, you can also do this: > > > > $db->getConnection(); > > > > No need to execute a dummy query. The getConnection() method > > initiates > > the connection if one has not already been made. > > > > Regards, > > Bill Karwin > > > > > -----Original Message----- > > > From: Jude Aakjaer [mailto:[EMAIL PROTECTED] > > <mailto:[EMAIL PROTECTED]>] > > > Sent: Monday, March 19, 2007 2:09 AM > > > To: Zend Framework General > > > Subject: Re: [fw-general] Zend_Db Exception throwing? > > > > > > Excellent thanks. I've added in a "SELECT 1" query inside my > > try/catch > > > block to grab a connection error now > > > > > > -Jude A. > > > > > > On Mon, 19 Mar 2007 17:11:54 +0900, Alexander Netkachev > > > <[EMAIL PROTECTED] > > <mailto:[EMAIL PROTECTED]>> wrote: > > > > > > > Zend_Db_Adapter does not create a connection to the database > when > > you > > > > create > > > > it. The "real" PDO Connection is created when you execute first > > query or > > > > create instance of Zend_Db_Table class. So, the try/catch > > block does > > not > > > > catch this exception just because it is fired later in the code, > > when > > > the > > > > "real" connection is created. > > > > > > > > Sincerely, > > > > > > > > > > >
