Search code examples
phpcentos7snowflake-cloud-data-platformunixodbc

PHP Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Can't open lib. Connection to Snowflake in php is not working but isql connection is


I am able to connect and query with isql to my snowflake server but when I attempt to do so with a php odbc_connect I get the following error.

PHP Warning:  odbc_connect(): SQL error: [unixODBC][Driver Manager]Can't open lib '/var/www/html/odbc_test/snowflake/snowflake_odbc/lib/libSnowflake.so' : file not found, SQL state 01000 in SQLConnect in /var/www/html/test/snowflake.php on line 29

I've never set up a odbc connection before and followed the snowflake provided guide here https://docs.snowflake.com/en/user-guide/odbc-linux.html.

The first thing I tried when after getting the error was to set the permissions on /var/www/html/odbc_test/snowflake/snowflake_odbc/lib/libSnowflake.so that did not work so I then set to to 777, still didn't work.

Here is the php code.

<?php
//values checked with https://docs.snowflake.com/en/user-guide/odbc-parameters.html
$SNOWFLAKE_HOST = 'snowflakecomputing.com';
$SNOWFLAKE_ACCOUNT = 'xxxx;
$SNOWFLAKE_PORT = '443';
$SNOWFLAKE_SCHEMA = 'xxxx';
$SNOWFLAKE_WAREHOUSE = 'xxxx';
$SNOWFLAKE_DATABASE = 'xxxx';
$SNOWFLAKE_USER = 'xxxx';
$SNOWFLAKE_PASSWORD = 'xxxx';



$dsn = "Driver=SnowflakeDSIIDriver;Server=" . $SNOWFLAKE_HOST;
$dsn .= ";Account=" . $SNOWFLAKE_ACCOUNT;
$dsn .= ";Port=" . $SNOWFLAKE_PORT;
$dsn .= ";Schema=" . $SNOWFLAKE_SCHEMA;
$dsn .= ";Warehouse=" . $SNOWFLAKE_WAREHOUSE;
$dsn .= ";Database=" . $SNOWFLAKE_DATABASE;

$conn_id = odbc_connect($dsn, $SNOWFLAKE_USER, $SNOWFLAKE_PASSWORD);
odbc_exec($conn_id, "USE WAREHOUSE " . $SNOWFLAKE_WAREHOUSE);

$res = odbc_exec($conn_id, 'SHOW TABLES IN SCHEMA ' . $SNOWFLAKE_SCHEMA . ';');
if ($res) {
    print "Tables in schema\n";
    while($row = odbc_fetch_array($res)) {
        print_r($row);
    }
}

$res = odbc_exec($conn_id, 'SELECT * FROM TEST;');
if ($res) {
    print "Test table content\n";
    while($row = odbc_fetch_array($res)) {
        print_r($row);
    }
}

enter image description here


Solution

  • I was able to resolve this by also changing the permissions of all of the directories in snowflake_odbc to 777.