0

我正在使用 PDO 连接到数据库,但它返回此错误:

致命错误:在 C:\AppServ\www\php-learn\cms project\lib\database.class.php:19 中未捕获的异常“PDOException”和消息“找不到驱动程序” 堆栈跟踪:#0 C:\AppServ\ www\php-learn\cms project\lib\database.class.php(19): PDO->__construct('mysql://hostnam...', 'root', '00000') #1 C:\AppServ \www\php-learn\cms project\config.php(49): database::get_instance() #2 {main} 在 C:\AppServ\www\php-learn\cms project\lib\database.class 中抛出。第 19 行的 php

文件database.class.php

class database
{
    // static  تستخدم عندما نريد استخدام الكلاس دون انشاء اوجيكت
    // () $ ! ~ & ^
    private static $db_connect;

    private function __construct()
    {} //

     // دالة لعمل اتصال ب قاعدة البيانتا

    // self ==> تشير الى اللاكلاس نفسة
    public static function get_instance()
    {
        if(null === self::$db_connect){

            self::$db_connect = new PDO
            ('mysql://hostname='.DB_HOST.';dbname=' . DB_NAME,
             DB_USER,
             DB_PASS);
        }
        return self::$db_connect;
    }

}

文件config.php

// Start buffering  ==> the first function in the appliction
ob_start();
ini_set('display_errors', 1);
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
ini_set('register_globals', 0);
define("DS",DIRECTORY_SEPARATOR);
define("PS",PATH_SEPARATOR); // WINDOWS = ; , LUNIX = ,
define("HOST_NAME", 'http://' . $_SERVER['HTTP_HOST'] . '/'); // DOMAIN NAME

// Paths
define("APP_PATH", realpath(dirname(__file__)) . DS);
define("TEMPLATE_PATH", APP_PATH . 'template' . DS);
define("LIB_PATH", APP_PATH . 'lib' . PS);

// Database
define("DB_HOST", "localhost");
define("DB_NAME", "cms_project");
define("DB_USER", "root");
define("DB_PASS", "00000");


$newpath = get_include_path() . PS . LIB_PATH; // Define new path
set_include_path($newpath);

function __autoload($class)
{
    require_once strtolower($class) . '.class.php';
}

$db_connect = database::get_instance();

// End the buffering
ob_flush();
4

0 回答 0