KKSzymanowski / laravel-6-odbc

9 stars 2 forks source link

Connecting with Pervasive SQL v11 64 Bit ODBC #5

Closed stemithy closed 3 years ago

stemithy commented 3 years ago

I have no trouble connecting using standard PHP ODBC Connection:

$odbc_conn = odbc_connect ( 'DRIVER={Pervasive ODBC Interface};SERVERname=MyServer;DBQ=@MyDB' , 'USERNAME' , 'PASSWORD' );
$odbc_exec = odbc_exec($odbc_conn,"select max(RecordNumber) from MPI");

But within the same Laravel 8 app using this package, I cannot find a value for dsn that doesn't throw "PDOException could not find driver". I understand if v11 is just not supported, but I thought I would check:

        'odbc' => [
            'driver' => 'odbc',
            'dsn' => "odbc:DRIVER={Pervasive ODBC Interface};SERVERname=MyServer;DBQ=@MyDB",
            'host' => 'MyServer',
            'username' => 'USERNAME',
            'password' => 'PASSWORD',
            'database' => 'MyDB',
        ],

Thanks,

KKSzymanowski commented 3 years ago

What operating system are you running this app on?

I have created this package to connect specifically to Pervasive SQL so it should work but I always had many issues with the set up.

KKSzymanowski commented 3 years ago

If you're running this on Linux then maybe this will help you. I have created a Docker image for apps using Pervasive SQL some time ago. It's for Ubuntu 18, PHP 7.4 and Pervasive 12 but it shouldn't be much different for PHP 8 and Pervasive 11.

Dockerfile

The $PSQL_FILE variable refers to the Pervasive driver downloaded from their website.

Here's an example content for these files:

COPY config/odbc.ini /etc/odbc.ini
COPY config/odbcinst.ini /etc/odbcinst.ini

odbc.ini:

[MyConnectionName]
Driver=Pervasive12
Description="Pervasive ODBC Interface"
ServerDSN=DSN
ServerName=192.168.0.1
DBQ=DATABASE_NAME
UID=USER_NAME
PWD=USER_PASSWORD
OpenMode=0
PvTranslate=

odbcinst.ini:

[Pervasive12]
Driver=/usr/local/psql/lib64/libodbcci.so
Driver64=/usr/local/psql/lib64/libodbcci.so

Here's the relevant portion of the .env file:

DB_PERVASIVE_DRIVER=odbc
DB_PERVASIVE_USERNAME="USER_NAME"
DB_PERVASIVE_PASSWORD="USER_PASSWORD"
DB_PERVASIVE_CONNECTION_STRING="odbc:MyConnectionName"

Here's my config in Laravel:

'MyConnectionName' => [
    'driver'   => env('DB_PERVASIVE_DRIVER'),
    'dsn'      => env('DB_PERVASIVE_CONNECTION_STRING'),
    'host'     => '',
    'database' => '',
    'username' => env('DB_PERVASIVE_USERNAME'),
    'password' => env('DB_PERVASIVE_PASSWORD'),
],
stemithy commented 3 years ago

This Laravel 8 Instance is running on Windows Server 2016 / IIS7 / MSSQL 2016 / PHP 7.4.1 The ODBC driver is Pervasive 11.30.51.00 (ODBCCI64.dll). It's really odd. I'm currently using the db config that throws "could not find driver" in the odbc package to successfully connect with odbc_connect. Please let me know if you have any other insight or would like more information about my instance.

Thanks for your help,

KKSzymanowski commented 3 years ago

Does the "could not find driver" error refer to the odbc driver in Laravel or to the Pervasive driver for ODBC?

stemithy commented 3 years ago

If I remove "odbc:" from the dsn value in the db config I get the error "Invalid data source name" and the stack trace contains several references to this package (like C:\inetpub\wwwroot\moss\vendor\kkszymanowski\laravel-6-odbc\src\OdbcConnector.php). I thought maybe there was a permission issue with the IIS user, but that wouldn't explain why odbc_connect works with the same connection string.

stemithy commented 3 years ago

The "could not find driver" error is being thrown from C:\inetpub\wwwroot\moss\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70. So, it does appear like it doesn't know what to do with 'driver'=>'odbc'.

stemithy commented 3 years ago

DUH.... I had to add extension=php_pdo_odbc.dll to my php.ini and it's working now. Thanks again for your help!

BTW... I had extension=php_odbc.dll in my php.ini which is why odbc_connect was working and the package was not.

KKSzymanowski commented 3 years ago

I love these kinds of errors. 😄 I should probably add pdo_odbc to the required list of extensions in composer.json.

stemithy commented 3 years ago

I know exactly what you mean. It’s like, “I know that my code isn’t causing this….but maybe…”, then BAM…”nope, external issue!”. Thanks again for helping me think through it.

From: Kuba Szymanowski notifications@github.com Reply-To: KKSzymanowski/laravel-6-odbc reply@reply.github.com Date: Tuesday, November 17, 2020 at 9:12 AM To: KKSzymanowski/laravel-6-odbc laravel-6-odbc@noreply.github.com Cc: Stephen Dukes stephen@melloncg.com, State change state_change@noreply.github.com Subject: Re: [KKSzymanowski/laravel-6-odbc] Connecting with Pervasive SQL v11 64 Bit ODBC (#5)

I love these kinds of errors. 😄 I should probably add pdo_odbc to the required list of extensions in composer.json.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHubhttps://github.com/KKSzymanowski/laravel-6-odbc/issues/5#issuecomment-728993054, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACQ346CUTK7LVT6NGPYAVT3SQKHFVANCNFSM4TXOVV4A.