• 26-01-2023, 21:01:18
    #1
    Merhabalar, veri tabanı bilgileri için database.php adında bir dosya oluşturup, bağlantı bilgilerini bu dosya içerisinde yer alan bir diziden çekerek bağlantı kurmak istiyorum. Fakat "Could not find driver" hatası alıyorum. Kodlar aşağıdaki gibidir, neyi hatalı yapıyor olabilirim?

    Hata: Could not find driver

    Yardımcı olabilecek birileri varsa çok sevinirim.

    database.php
    function database(){
    
        $charset= 'utf8';
        $host = 'localhost';
        $port = '80';
        $user = 'root';
        $password = '';
    
        return $data = array(
            ':host' => $host,
            ':port' => $port,
            ':user' => $user,
            ':password' => $password,
            ':charset ' => $charset
        );
    }
    config.php
        require_once 'database.php';
    
        $connection = new PDO('
            mysql:host='.database()[':host'].';
            charset='.database()[':charset'].',
            '.database()[':user'].',
            '.database()[':password'].'
        ');
  • 26-01-2023, 21:06:34
    #2
    database.php

    return[
        'db' => [
            'name' => 'lisans',
            'host' => 'localhost',
            'user' => 'root',
            'pass' => ''
        ]
        ];
    config.php

    //DB Bilgileri ve Bağlantısı
    $config = require __DIR__ . '/config.php';
    try
    {
        $db = new PDO('mysql:host=' . $config['db']['host'] . ';dbname=' . $config['db']['name'], $config['db']['user'], $config['db']['pass']);
    }
    catch (PDOException $e)
    {
        die($e -> getMessage());
    }
    Olarak deneme yapar mısın?
  • 26-01-2023, 21:17:12
    #3
    FurkanAkman adlı üyeden alıntı: mesajı görüntüle
    database.php

    return[
        'db' => [
            'name' => 'lisans',
            'host' => 'localhost',
            'user' => 'root',
            'pass' => ''
        ]
        ];
    config.php

    //DB Bilgileri ve Bağlantısı
    $config = require __DIR__ . '/config.php';
    try
    {
        $db = new PDO('mysql:host=' . $config['db']['host'] . ';dbname=' . $config['db']['name'], $config['db']['user'], $config['db']['pass']);
    }
    catch (PDOException $e)
    {
        die($e -> getMessage());
    }
    Olarak deneme yapar mısın?
    İlginize teşekkür ederim hocam, bu şekilde bağlantı alabiliyorum.