对于抽象类命名空间,我得到了一个错误“'Piksel \ Modules \ DB \ PDO'未找到”

时间:2013-06-02 08:36:12

标签: php pdo namespaces abstract-class

我想为may项目使用命名空间,但我遇到了问题。 我收到了类似的错误

  

“致命错误:未找到类'Piksel \ Modules \ DB \ PDO'   C:\ XAMPP \ htdocs中\包括\模块\数据库\ DataBasePDO.php   在第23行“

这是我的index.php代码;

use Piksel\Modules\DB;
require_once("includes/require.php");


class Main extends DB\DataBase
{
    static function getdata()
    {

    }
}

$db = Main::getInstance();

和DataBasePDO.php代码是;

    <?php namespace Piksel\Modules\DB; ?>
    <?php

    require_once(sprintf("%s/IDataBase.php", __DIR__));
    require_once(sprintf("%s/DataBaseParam.php", __DIR__));
    require_once(sprintf("%s/QueryMaker.php", __DIR__));

abstract class DataBase extends QueryMaker implements IDataBase
{   
    protected static $instance = null;
    protected $DBH;
    protected $STH;

    public static function getInstance()
    {
        if (!isset(self::$instance)) self::$instance = new static();

        return self::$instance;
    }

    function __construct() 
    {
        $dsn = sprintf("mysql:host=%s;port=%s;dbname=%s;", $this->getHostName(), $this->getPort(), $this->getDbName());

        try 
        {
            $this->DBH = new \PDO($dsn, $this->getUserName(), $this->getPassword(), array(\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
            $this->DBH->setAttribute(\PDO::ATTR_PERSISTENT, true);
            $this->DBH->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
        } 
        catch (\PDOException $e)
        {
            $this->errorMessage($e);

            die();
        }
    }
    }

感谢您的进步。

0 个答案:

没有答案