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,
    > >
    >



Reply via email to