leafsphp / db

🗄 Leaf PHP db module
https://leafphp.dev/modules/db/
6 stars 11 forks source link

Connecting sql server #6

Closed andrew-m-p closed 1 year ago

andrew-m-p commented 1 year ago

Could not connect to sql server , I had to modify this function and add 'sqlsrv' to make it work

protected function dsn(): string { $dbtype = $this->config('dbtype'); $dbname = $this->config('dbname'); $host = $this->config('host');

    if ($dbtype === 'sqlite') {
        $dsn = "sqlite:$dbname";
    }
    else if ($dbtype === 'sqlsrv') {
        $dsn =  $dbtype.":Server=".$this->config('host');
        $dsn .= ";Database=".$this->config('database');    
    } else {
        $dsn = "$dbtype:host=$host";
        if ($dbname !== '') $dsn .= ";dbname=$dbname";
        if ($this->config('port')) $dsn .= ';port=' . $this->config('port');
        if ($this->config('charset')) $dsn .= ';charset=' . $this->config('charset');
        if ($this->config('unixSocket')) $dsn .= ';unix_socket=' . $this->config('unixSocket');
    }

    return $dsn;
}
mychidarko commented 1 year ago

Hi @andrew-m-p, thanks for pointing this out. I'll check out your issue.

mychidarko commented 1 year ago

This has been added now. Will be available from the next release