0

Fatal error: Uncaught PDOException: could not find driver in C:\xampp\htdocs\API\api\Api.php:19 Stack trace: #0 C:\xampp\htdocs\API\api\Api.php(19): PDO->__construct('\r\n \t\t\tmysql:hos...', 'root', '') #1

This is how i connect my php to database connection

class API
{
private $connect = '';

// Inisiasi 
function __construct() {
    $this->database_connection();
}

function database_connection(){
    $this->connect = new PDO("
        mysql:host=localhost;
        dbname=api",
        "root",
        "");

}
....
}

I already added pdo my php.ini like this

extension=php_pdo.dll
extension=php_pdo_mysql.dll
extension = mysqlnd.so
extension = pdo.so
extension = pdo_mysql.so
extension=bz2
extension=curl
extension=fileinfo
extension=gd2
extension=gettext
;extension=gmp
;extension=intl
;extension=imap
;extension=interbase
;extension=ldap
extension=mbstring
extension=exif      ; Must be after mbstring as it depends on it
extension=mysqli
;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client
;extension=odbc
;extension=openssl
extension=pdo_firebird
extension=pdo_oci
extension=pdo_odbc
extension=pdo_pgsql
extension=pdo_sqlite
;extension=pgsql
;extension=shmop

but error still occurs

Togan J.R
  • 99
  • 1
  • 13
  • Are you restarted the server? – Dmitry Leiko Dec 04 '19 at 11:10
  • maybe its because of the whitespace, `\r\n \t\t\t` is not a pdo driver. mangled.. you cant simply uncomment the lines in php.ini you still have to install the php-mysql extension, which should handle enabling the modules for you, also .dll wont work on linux, .so wont work on windows – Lawrence Cherone Dec 04 '19 at 11:21
  • @Dmitry yes i have restarted my server – Togan J.R Dec 04 '19 at 11:29
  • @LawrenceCherone if iam using windows that means .dll will work right ? and also how to install php-mysql extension in windows iam using xampp because i only simply uncomment lines (but for extension=php_pdo.dll extension=php_pdo_mysql.dll i add them) and restarted server my xampp is the lastest one v 3.2.4 – Togan J.R Dec 04 '19 at 11:29
  • xampp should have everything you need enabled already, revert the php.ini to what it was before edits, restart apache. Then remove the whitespace from your code. – Lawrence Cherone Dec 04 '19 at 11:38
  • @LawrenceCherone thanks you , i revert my php.ini back and removed the whitespace and everything is working now – Togan J.R Dec 04 '19 at 11:46

1 Answers1

0

Edit answer : its because of the whitespace, \r\n \t\t\t is not a pdo driver

Togan J.R
  • 99
  • 1
  • 13