我正在使用pdo连接到database.but返回此错误
Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:\AppServ\www\php-learn\cms project\lib\database.class.php:19 Stack trace: #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} thrown in C:\AppServ\www\php-learn\cms project\lib\database.class.php on line 19
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 buffring ==> 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 buffring
ob_flush();