0

我想为可能的项目使用命名空间,但我遇到了问题。我遇到了这样的错误

“致命错误:在第 23 行的 C:\xampp\htdocs\includes\modules\database\DataBasePDO.php 中找不到类 'Piksel\Modules\DB\PDO'”

这是我的 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();
        }
    }
    }

谢谢你的先进。

4

0 回答 0