Ammad Nazir
Ammad Nazir

Reputation: 161

PDO Exceptions could not find driver

PDO Exceptions could not find driver

here is my function

class Database extends PDO {

public function __construct() {
    try{
    parent::__construct(DB_TYPE . ':host=' . DB_HOST . ';dbname=' . $DB_NAME, DB_USER, DB_PASS);
    } catch (Exception $e){
        echo '<pre>';
        echo 'Message:' .$e->getMessage().'<br>';
        echo 'Message:' .$e->getTraceAsString().'<br>';
        print_r(get_loaded_extensions());
        echo '</pre>';
    }

}

and I am getting

could not find a driver

0 /home/dltechi/public_html/dating/libs/Database.php(11):
PDO->__construct('DB_TYPE:host=DB...', 'DB_USER', 'DB_PASS') 1 /home/dltechi/public_html/dating/libs/Model.php(6):
Database->__construct('DB_TYPE', 'DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS') 2 /home/dltechi/public_html/dating/libs/Controller.php(22): Model->__construct() 3 /home/dltechi/public_html/dating/libs/Bootstrap.php(103):
Controller->useModel('test', 'models/') 4 /home/dltechi/public_html/dating/libs/Bootstrap.php(30):

 Bootstrap->_loadExistingController()
5 /home/dltechi/public_html/dating/index.php(83): Bootstrap->init()
6 {main}

Upvotes: 0

Views: 119

Answers (1)

Bhupendra Thapa
Bhupendra Thapa

Reputation: 1

I am using laragon FOR LARAVEL and was facing same problem but i figured it out...And My php version is 7.2 For the older versions uncomment the php_pdo_mysql & mysql.dll (make sure u are using pgsql/pgmysqllite or any other and uncomment them and for non used ones you have to use';'

CHECK THE PATH IN ENVVIRONMENT VARIABLES. and version >7

undo all the extensions in php.ini except for THE

extension=pdo_mysql

Because the latest versions are encoded without the 'php_pdo_mysql & other .dll' files & are already i compiled i guess. ESPECIALLYY FOR THE {{PDO_****}} disable them & enable above code..and ';'

With doing that u can change your utf8mbg to utf8 respecitvely to both charset and collation:

inside app\config\database.php set the default to 'mysql'.

------>>app\config\database.php & set the default to 'mysql'

'mysql' => [ **** others are same just change the following]

'charset' => 'utf8',
    'collation' => 'utf8_unicode_ci',

Upvotes: 0

Related Questions