Sunday, 8 September 2013

pdo error in php " Fatal error: Uncaught exception 'PDOException' with message 'could not find driver "

pdo error in php " Fatal error: Uncaught exception 'PDOException' with
message 'could not find driver "

I am using pdo to connect to database.but return this error " 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 file code
is: 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 file code is:
// 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();

No comments:

Post a Comment