-- Louie Miranda <[email protected]> wrote
(on Tuesday, 29 June 2010, 02:50 PM +0800):
> I am trying ZF as a loose class, but I am failing when connecting to a db.
> 
> I have added the ZF library on php.ini includes and created a file.
> 
> test01.php
> 
> <?php
> require_once 'Zend/Db.php';
> $db = new Zend_Db_Adapter_Pdo_Mysql(array(
>     'host'     => '192.168.1.33',
>     'username' => 'dba',
>     'password' => 'pass',
>     'dbname'   => 'database'
> ));
> 
> print_r($db);
> ?>
> 
> The error is, PHP Fatal error:  Class 'Zend_Db_Adapter_Pdo_Mysql' not found

As others have noted, using the autoloader can and will solve this
problem.

That said, another way you could have solved the issue is to use
Zend_Db's factory to instantiate your adapter:

    require_once 'Zend/Db.php';
    $db = Zend_Db::factory('pdo_mysql', array(
        'host'     => '192.168.1.33',
        'username' => 'dba',
        'password' => 'pass',
        'dbname'   => 'database'
    ));

This accomplishes the same thing, but doesn't require that the adapter
class be loaded first.

-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

Reply via email to