Skip to content

sqlsrv not working with Debian 12 #1030

@yoramdelangen

Description

@yoramdelangen

Not sure where to put the "issue" because I dont know if its a bug or something else.

I have compiled a PHP 8.4.17 x86_64-gnu version with sqlsrv and pdo_sqlsrv. With a simple test script I was testing to make a connection to a SQL Server on a Debian 12 environment (Azure). Very plain an simple:

// test.php
<?php

$server   = "a-remote-sqlsrv-url,3342";
$database = "my_database";
$username = "sqlsrv_dbo";
$password = "a-very-strong-password";

$dsn = "sqlsrv:Server=$server;Database=$database;TrustServerCertificate=true;Encrypt=true";
echo 'Connecting to '. $server;
try {
    $pdo = new PDO($dsn, $username, $password, [
        PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    ]);

    echo "Connected to SQL Server successfully!";
} catch (PDOException $e) {
    die("Connection failed: " . $e->getMessage());
}

I have been testing this command with a 'statically compiled binary' and a PHP installed via apt:

# static binary call
./php-gnu test.php

# system binary call
php test.php

When running the static binary it will timeout after (a lot of seconds) Connecting to {server host},{port}.
When running the system PHP 8.4. (which is the same version as the static binary) it succeeds the connection and I see "Connected to SQL Server successfully" without any problems.

I noticed that the offical pdo_sqlsrv and sqlsrv driver didn't have support for Debian 12 yet. This has been recently been added. The pre-built binaries that can be used via the workflows are containing the previous version (5.12.0), so we build all dependencies from scratch and tested the above commands with that new version as well. Result still timeout.

We tested this in a Debian 12 Docker image, same issue. Tested it with Ubuntu 24.04, and it works perfectly fine, conclusion it has something to do with Debian.

Note: the drivers require you to install the msodbcsql17 or msodbcsql18.

Re-installed drivers, unixodbc, it dependencies, msodbcsql1X etc. but didn't make any difference. Also check if it was a certificate problem(ca-certificate), because of the timeout but no difference. Re-installed openssl 3 and considered to install openssl 1.1 but no difference either.

After that I started watching the LIB lookup trace with LD_DEBUG=libs,files the only difference between the system PHP and static PHP was the way it loads the msodbcsql driver.

#system php: 
$ LD_DEBUG=libs,files php test.php
file=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.6.so.1.1 [0];  dynamically loaded by /lib/x86_64-linux-gnu/libltdl.so.7 [0]
      3557:     file=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.6.so.1.1 [0];  generating link map
      3557:       dynamic: 0x000079450fb54360  base: 0x000079450f954000   size: 0x000000000021a840
      3557:         entry: 0x000079450f971500  phdr: 0x000079450f954040  phnum:                 11
      3557:
      3557:
      3557:     file=libdl.so.2 [0];  needed by /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.6.so.1.1

# static php:
$ LD_DEBUG=libs,files ./php-gnu test.php
file=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.6.so.1.1 [0];  dynamically loaded by ./php-gnu [0]
      3561:     file=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.6.so.1.1 [0];  generating link map
      3561:       dynamic: 0x000077a11389a360  base: 0x000077a11369a000   size: 0x000000000021a840
      3561:         entry: 0x000077a1136b7500  phdr: 0x000077a11369a040  phnum:                 11
      3561:
      3561:
      3561:     file=libodbcinst.so.2 [0];  needed by /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.6.so.1.1 [0]

I am stuck on this problem for a couple of days straight, and need some fresh ideas on how to approach/resolve it. Could it be something with one of the static dependency that are compiled into the binary, or a very hard Debian issue?

Any suggestions are welcome!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingkind/dependencyIssues related to dependenciesos/linuxThings only for Linux OS

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions