0

I am trying to connect to MS SQL database to pull some data and import to my MySQL DB. I am using the latest version Laravel 9 with Laravel Sail. Here are the steps I took

sail artisan sail:publish to publish Docker and then in the Docker folder under 8.1 (PHP version I use) in Dockerfile i added the following

# Add repository ODBC and Install the Microsoft ODBC driver for SQL Server
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
    && curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list > /etc/apt/sources.list.d/mssql-release.list \
    && apt-get update \
    && ACCEPT_EULA=Y apt-get install -y msodbcsql18 \
    && ACCEPT_EULA=Y apt-get install -y mssql-tools18 \
    && apt-get install -y unixodbc-dev

# Install the PHP drivers for Microsoft SQL Server

RUN curl -O https://pear.php.net/go-pear.phar \
     && php go-pear.phar

RUN pecl install sqlsrv \
    && pecl install pdo_sqlsrv \
    && su \
    && printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/8.1/mods-available/sqlsrv.ini \
    && printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/8.1/mods-available/pdo_sqlsrv.ini \
    && exit \
    && phpenmod -v 8.1 sqlsrv pdo_sqlsrv 

Then I ran sail build --no-cache and everything finished with no error

But when I try to connect to the DB I get could not find driver error

Note: I also have all the DB variables set in my .env file

nick
  • 1
  • 3
  • Fixed this by `# Install the PHP drivers for Microsoft SQL Server` `RUN pecl config-set php_ini /etc/php/8.1/fpm/php.ini \` ` && pecl install sqlsrv \` ` && pecl install pdo_sqlsrv \` ` && su \` ` && printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/8.1/mods-available/sqlsrv.ini \` ` && printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/8.1/mods-available/pdo_sqlsrv.ini \` ` && exit \` ` && phpenmod -v 8.1 sqlsrv pdo_sqlsrv` and adding `RUN apt-get install freetds-common freetds-bin unixodbc php8.1-sybase ` – nick Sep 20 '22 at 22:14

1 Answers1

0

Not sure if this could help but a few years ago I was able to connect a PHP web site (Laravel) with a MS SQL Server.

And the only drivers that were working was from Microsoft repository on Git : https://github.com/Microsoft/msphpsql/releases.

Note : The web site was running on a MS Windows Server.

Cordially, rv.

arcturien
  • 11
  • 3