SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified

1

I am running a PHP script on a RedHat server using Teradatas ODBC drivers.

<?php

$conn = odbc_connect("Teradata", "username", "password");
$result = odbc_exec($conn, 'SELECT count(*) FROM table');

while (odbc_fetch_row($result)) {
    for ($i = 1; $i <= odbc_num_fields($result); $i++) {
        echo "Result is ".odbc_result($result,$i);
    }
}

?>

I have run strace on the script and found that it's looking for the .ini files which hold the DNS information in the wrong location as well as putting a . before the file name.

open("/home/a-taslam/.odbcinst.ini", O_RDONLY) = -1 ENOENT (No such file or directory)

It should be looking for the file at /opt/teradata/client/ODBC_64/odbcinst.ini

Does anyone know how to correct this?

ChristopherStrydom

Posted 2015-08-20T14:23:00.190

Reputation: 133

Answers

2

You just need to set and export the ODBCSYSINI environment variable --

export ODBCSYSINI=/opt/teradata/client/ODBC_64/

or

set ODBCSYSINI=/opt/teradata/client/ODBC_64/ ; export ODBCSYSINI

Note -- this environment variable must be set for php when it's running, whether php inherits the setting from its launch environment, or you add this setting to the PHP configuration files.

TallTed

Posted 2015-08-20T14:23:00.190

Reputation: 419