简体   繁体   中英

Zend_Db not found

use Zend\Db;

$db = Zend_Db::factory('Pdo_Mysql', array(
    'host'     => 'localhost',
    'username' => 'root',
    'password' => '',
    'dbname'   => 'test'
));

I'am trying to require Zend_Db by the keyword 'use', but i get An error that there are not class Zend_Db, what i am doing wrong here?

If you are using ZF1, then the class is Zend_Db . In this case, if you really want to use PHP 5.3 namespaces, then the correct usage is:

use \Zend_Db;

$db = Zend_Db::factory('Pdo_Mysql', array(
    'host'     => 'localhost',
    'username' => 'root',
    'password' => '',
    'dbname'   => 'test'
));

If you are using ZF2, then the relevant component is Zend\\Db , but creating adapters there is typically done using factories defined in module config .

And, as noted elsewhere, figuring out autoloading makes life a lot easier.

在文件开头添加此

   require_once 'Zend/Db.php';

Zend Framework 1.x predates PHP namespaces by some time. As a result ZF1 is not really friendly to things like the use keyword. If you need to use components of Zend Framework 1.x you will likely be better served by using the included autoloader component .

If you are using the framework as an MVC application then this whole thing is moot and I recommend you take some time and learn how the default configuration works. Because if you're using ZF1 as an MVC the Zend_Db component will already be on the autoloader.

Don't mix underscore names with slashes

use Zend_Db as Db

$db = Db::factory('Pdo_Mysql', array(
    'host'     => 'localhost',
    'username' => 'root',
    'password' => '',
    'dbname'   => 'test'
));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM