Skip to content

Commit

Permalink
Connection working.
Browse files Browse the repository at this point in the history
* Had to force x86 arch because Databricks driver doesn't support ARM yet
* See https://stackoverflow.com/questions/69575145/01000-01000-unixodbcdriver-managercant-open-lib-opt-simba-spark-li
  • Loading branch information
rlorenzo committed Feb 28, 2022
1 parent b28da2d commit cb04ff9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:7.4-cli
FROM --platform=linux/amd64 php:7.4-cli

RUN apt-get update \
&& apt-get install wget unzip git unixodbc unixodbc-dev libpq-dev -y
Expand All @@ -19,7 +19,7 @@ RUN set -x \
# Quite sure this stuff is necessary - it just installs a bunch of php pdo extensions
RUN set -x \
&& apt-get install -y unixodbc unixodbc-dev freetds-dev freetds-bin tdsodbc \
&& if ! [ -h /usr/lib/libsybdb.a ]; then ln -s /usr/lib/aarch64-linux-gnu/libsybdb.a /usr/lib/; fi \
&& if ! [ -h /usr/lib/libsybdb.a ]; then ln -s /usr/lib/x86_64-linux-gnu/libsybdb.a /usr/lib/; fi \
&& docker-php-ext-install pdo \
&& docker-php-ext-install pdo_dblib \
&& docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixODBC,/usr \
Expand Down
25 changes: 22 additions & 3 deletions test_connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,45 @@
$user = 'token';
// NOTE $password is defined in config.php.

// First try to connect via ODBC.
// Try to connect via ODBC.
echo "Trying ODBC connection...\n";
$odbc = odbc_connect($dsn, $user, $password);
// Checking connection id or reference
if (!$odbc) {
echo "ODBC connect failed: " . odbc_error() . "\n";
} else {
echo "ODBC connection successful!\n";

$sql = 'SHOW DATABASES';
echo 'Query: ' . $sql . "\n";
$results = odbc_exec($odbc, $sql);
while (odbc_fetch_row($results)) {
for ($i=1; $i<=odbc_num_fields($results); $i++) {
echo odbc_result($results, $i) . "\n";
}
}

// Resource releasing
odbc_close($odbc);
}

// Next try PDO.
try {
echo "\n\nTrying PDO connection...\n";
echo "\nTrying PDO connection...\n";
$dsn = 'odbc:Databricks';
$pdo = new PDO($dsn, $user, $password);
echo "PDO connection successful!\n";

$sql = 'SHOW DATABASES';
echo 'Query: ' . $sql . "\n";
$results = $pdo->query($sql);
foreach ($results as $row) {
echo $row[0] . "\n";
}

} catch (Exception $e) {
echo "PDO connection failed: " . $e->getMessage() . "\n";
}

echo "DONE!\n";

echo "\nDONE!\n";

0 comments on commit cb04ff9

Please sign in to comment.