Search code examples
phpzend-framework2zend-db

What more could be required for Zend_Db to load?


In my project directory, I have installed composer, and set up composer.json like so:

{
    "repositories": [
        {
            "type": "composer",
            "url": "https://packages.zendframework.com/"
        }
    ],
    "require": {
       "zendframework/zend-db": "2.0.*"
    }
}

And run:

$ php composer.phar install

which seemed to complete fine. In a file Database.php in my project directory, I have:

require_once 'vendor/autoload.php';

// Automatically load class Zend_Db_Adapter_Pdo_Mysql
// and create an instance of it.
$db = Zend_Db::factory('Pdo_Mysql', array(
    'host'     => "host",
    'username' => "username",
    'password' => "password",
    'dbname'   => "dbname"
));

But when I run this script, I get:

$ php Database.php
PHP Fatal error:  Class 'Zend_Db' not found in /path/project/Database.php on line 4
PHP Stack trace:
PHP   1. {main}() /path/project/Database.php:0

What I am missing for the script to find the 'Zend_Db' class?


Solution

  • You are doing wrong way. Zend_DB is ZF1 Library. It will not work with Zf2. You need to learn Zf2 DB/Adapter first.