uepg/laravel-sybase

ODBC

Opened this issue · 2 comments

Hi, do you have an example of using odbc with this package? I'm not sure how I would put my connection details in the database config file for it.

Sorry, we use it only as it' s described on README file. Never tried to connect it using ODBC.

My mistake. The package in its pre-alpha versions was intended for Windows, so the connection was made from ODBC, where it replicated the entire structure of the Laravel Database. If you go to: vendor/laravel/framework/src/Illuminate/Database/Connectors/SqlServerConnector.php and change the getDsn function to:

    protected function getDsn(array $config)
    {	
        $arguments = [
            'Driver' => '{Adaptive Server Enterprise}',
            'server' => $config['host'],
        ];
        if (isset($config['database'])) {
            $arguments['db'] = $config['database'];
        }
	if (isset($config['port'])) {
            $arguments['port'] = $config['port'];
        }	
        if (isset($config['appname'])) {
            $arguments['APP'] = $config['appname'];
        }
        return $this->buildConnectString($arguments);
    }

and buildConnectString to:

protected function buildConnectString(array $arguments)
    {
        $options = array_map(function ($key) use ($arguments) {
            return sprintf('%s=%s', $key, $arguments[$key]);
        }, array_keys($arguments));

        return 'odbc:'.implode(';', $options);
    }

It will probably work with ODBC. But note that it's a very very old code and certainly not the best solution. But it is implementable.