All Forums Connectivity
bobomagic 5 posts Joined 08/07
10 Aug 2007
Teradata ODBC driver with Apache/PHP

Has anyone successfully setup and run an Apache/PHP environment with the Teradata ODBC driver?I can get everything running, but odbc_connect() PHP calls result in segfaults in Apache. It's strange, because running php from the command line with the same php script works fine. Looking at the trace files, it looks like the authentication step is happening, and then poof.Any ideas of things to try?

mg1 1 post Joined 09/07
05 Sep 2007

I have XAMPP installed on my windows desktop and the odbc_connect with PHP works okay. I tried to run odbc_connect from Linux and got an error via the command line. I haven't tried the XAMPP install on Linux yet.

bobomagic 5 posts Joined 08/07
05 Sep 2007

I'm not sure why (though I think it has something to do with easing filesystem access restraints), but setting the Apache directive CoreDumpDirectory makes the setup work.

sebbs 2 posts Joined 02/08
27 Feb 2008

Ok, so here's my setup.Redhat ES 5Apache 2.2Php 5.14odbc 2.21Teradata driver 8.1....all rpms installed.when I run isql -v dbname dbuser dbpassword , I get this[ISQL]ERROR: Could not SQLConnectthrough php -> odbc_connect("edw_prod", "user", "password")I get this...popped into the apache error_logPHP Warning: odbc_connect() [ ]: SQL error: , SQL state 00000 in SQLConnect in (also the same for the user's .odbc.ini)[ODBC]InstallDir = /usr/odbcTrace = YesTraceDll = /usr/odbc/lib/odbctrac.soTraceFile = /edw/trace.logTraceAutoStop = 0[ODBC Data Sources]default = tdata.soedw_prod =[edw_prod]Driver = /usr/odbc/drivers/tdata.soDescription = EDW PROD 5380DSNTraceEnable = YesDBCName = serverIPLastUser = Username = userPassword = Database = prodDateTimeFormat = AAASessionMode = ANSI[ODBC DRIVERS]Teradata = InstalledTrace = YesUsageCount = 4[Teradata]Driver = /usr/odbc/drivers/tdata.soUsageCount = 2APILevel = COREConnectFunctions = YYYDriverODBCVer = 3.51SQLLevel = 1HOME=/edwTWB_ROOT=/opt/teradata/client/tbuild/, need your help ! been struggling in getting this working for over 3 days now.

sebbs 2 posts Joined 02/08
03 Mar 2008

no one have a setup like this at all???Linux/apache/php ?bunch of winblows users on here or what?

bobomagic 5 posts Joined 08/07
03 Mar 2008

My guess would be the programs are not finding the odbc files correctly. Use 'strace' to run isql and carefully look at the strace output to see if there are some necessary file isql can not find. This will take you time.

frider 3 posts Joined 03/11
17 Mar 2011

Hi, did you ever get the ODBC connection to Teradata from Apache and PHP to work? I am trying to do the same thing. I can use isql to connect to Teradata from the linux box and pull data, and I can run Teradata's 'adhoc' program and connection and pull data. But I cannot get php's odbc_connect() function to work. Looking at the detailed trace, it looks like somethign with the authentication, though I am properly passing username and password.


vhari 111 posts Joined 12/08
18 Mar 2011

Here is some information, how to build/install/configure and when Apache executes PHP as CGI binary :

It is important to build PHP against the DataDirect driver manager that is distributed with Teradata ODBC driver. For that reason make sure ODBC_HOME environment variable points to a correct folder. (showed below)

PHP configure looks header file odbc.h in the ODBC driver includes directory. So, make sure to create the header file with the file name odbc.h and add following lines in the file and save it:

#include <odbcinst.h>
#include <sql.h>
#include <sqlext.h>

(below steps used php ver 5.3.3)

> tar -xzf php-5.3.3.tar.gz
> cd php-5.3.3
> export ODBC_HOME=/opt/teradata/client/ODBC_32
> export CPPFLAGS="-I$ODBC_HOME/include"
> export CUSTOM_ODBC_LIBS="-L$ODBC_HOME/lib -lodbc -lodbcinst"
> ./configure --prefix=/usr/local/php --with-custom-odbc=$ODBC_HOME
> make <-- build
> make install <-- install

below are optional.

> php-cgi –v <-- to verify installation of PHP
> php-cgi –info <-- to see configuration information

Configuration of Apache server is controlled with httpd.conf file. Update the file to add support for PHP CGI scripts as follows:
Define a PHP CGI script directory alias, mapping an Apache document directory to a real directory where php-cgi binary is located. Inside <IfModule alias_module> section, add the following line to define a PHP CGI script directory alias:

> ScriptAlias /cgi-bin-php/ "/usr/local/php/bin/"

In the root of the document (outside of any section) add this access control section for this directory as:

<Directory "/usr/local/php/bin">
SetEnv ODBCINI "/ opt/teradata/client/ODBC_32/odbc.ini"
SetEnv ODBCINSTINI "/opt/teradata/client/ODBC_32/odbcinst.ini"
Options Indexes FollowSymlinks
AllowOverride None
Options None
Order allow,deny
Allow from all

Inside <IfModule mime_module> section, add the following to define a new MIME type to support the .php file extension. Next add “Action” entry to tell Apache to serve the new MIME type with php-cgi binary located in the directory alias /cgi-bin-php/:

AddType application/x-httpd-php .php
Action application/x-httpd-php "/cgi-bin-php/php-cgi"

Note the definition of ODBCINI and ODBCINST environment variables. Those variables are passed into PHP process during request handling. Alternatively, those variables can be defined within PHP script itself:


Restart the server:

> /usr/local/apache2/bin/apachectl restart

alexl.charter 5 posts Joined 08/11
26 Aug 2011


teradatatester 69 posts Joined 01/10
19 Oct 2011

Any suggestions for this error I am getting?


PHP Warning:  odbc_connect(): SQL error: [unixODBC][Driver Manager]Can't open lib '/opt/teradata/client/ODBC_32/lib/' : /opt/teradata/client/ODBC_32/lib/ wrong ELF class: ELFCLASS32, SQL state 01000 in SQLConnect in /home/username/helloWorld.php on line 8
PHP Warning:  odbc_exec(): supplied argument is not a valid ODBC-Link resource in /home/username/helloWorld.php on line 10

vhari 111 posts Joined 12/08
11 Nov 2011

It looks you odbc.ini file pointing to 32-bit ODBC Driver where as PHP is 64-bit.  Update odbc.ini to point to 64-bit driver, usually it is /opt/teradata/client/ODBC_64/lib/

WSix 1 post Joined 10/11
14 Mar 2012

Hi, I'm a complete dummy on php and making a connection to Teradata. I read carefully the above comments, but I cannot solve my problem. I hope someone can list up what is needed to make it work.

In short I want to make a odbc connection from php to a Teradata database. These are the product I installed:










Linux version 2.6.32-71.el6.x86_64 ( (gcc version 4.4.4 20100726 (Red Hat 4.4.4-13) (GCC) ) #1 SMP Wed Sep 1 01:33:01 EDT 2010

Webserver: Apache


The native odbc connection to the Teradata database, (the adhoc test) is working.


My php code is:






$rs=odbc_exec($conn, "select * from dbc.dbcinfo;");



Executing this small piece of code results in:

[id973285@el0861 html]$ php ws.php
odbcini =/home/ID973285/.odbc.ini
odbcinst =/home/ID973285/.odbcinst.ini
Segmentation fault (core dumped)

The content of my .odbc.ini file is:

[id973285@el0861 html]$ cat /home/ID973285/.odbc.ini

[ODBC Data Sources]

Description=Teradata running Teradata V1R5.2


Any help is more than welcome.


rmmangin 1 post Joined 07/12
03 Jul 2012

Using php 5.2.9 on Fedora Linux 2.6.27 I am able to successfully use odbc_connect(), odbc_tables(), and odbc_columns().  So I can connect to the database, see its tables, and see the columns for any table.  So far, so good.

However, when I use odbc_exec() to execute a simple SELECT statement, it gives "Memory fault" and drops me back to the shell.  I even tried putting the odbc_exec() inside a try...catch block, but found this is not a catchable exception.

Has anyone else seen this behavior?  Any suggestions?

Thanks in advance!

esca2791 1 post Joined 07/13
10 Oct 2013

Hi, I am attempting to use similar tools (Apache, PHP5, UnixODBC(v 2.3.0), and teradata) to connect.  I've tried installing Teradata ODBC drivers (versions) 12 through 14 and each installation (all 64 bit on my 64 bit machine) returns a segmentation fault error...which in isql results in a file not found.  Is there a reccomended version for Ubuntu users and a separate reccomendation for CentOS/RHEL users?
The Unix ODBC enters fine into my local mysql database.  It is just the module that is giving me trouble.
Thank you in advance.

rsfitzii 1 post Joined 10/13
04 Dec 2013

I had a lot of trouble getting the Teradata driver/php odbc to work as well, but recently I was able to get a successful compile of php and odbc seems to be working fine for accessing our Teradata db.

I followed the steps above posted by vhari on 18 Mar 2011. It does seem to be critical that you compile php using the custom ODBC config parameter to build in the Teradata software as opposed to the generic UnixODBC extension. Long story short, I finally got to the place that others have mentioned where I continued to get a seg fault or just an unknown generic database error when trying to connect with odbc_connect

After days of wrangling with my build and seeing references in other forums to there being conflicts between different php extensions (that at first I didn't think could possibly be my problem), I realized something very important about vhari's example above.

In that example, the only config option being used is the one to include the Teradata custom odbc library. So I ended up recompiling my php and removing things from my config each time until odbc_connect would work. It turns out that it was the oci8 (Oracle) client that I was also compiling into php that was the culprit. We've used the oci8 extension for years with no problem so I didn't even think the seg fault could be caused by something that existed within our current php build. But that's what it was, removing the oci8 library fixed the seg fault error. Luckily, you don't have to leave it removed. Teradata and oci8 can co-exist, but you must build php with oci8 as a shared extension to avoid the conflict between the two.

Anyway, hopefully this will help someone else.

msirek 3 posts Joined 06/09
06 Nov 2014

These posts really helped me in setting up php/odbc on apache.  One additional problem I found is that odbc would not work unless LD_LIBRARY_PATH is properly set before running the configure script for building php:

export LD_LIBRARY_PATH=/opt/teradata/client/15.10/odbc_64/lib:/opt/teradata/client/15.10/tdicu/lib:$LD_LIBRARY_PATH

export LD_LIBRARY_PATH_64=/opt/teradata/client/15.10/odbc_64/lib:/opt/teradata/client/15.10/tdicu/lib64:$LD_LIBRARY_PATH_64


If you are using a different client version than 15.10, substitute the appropriate path.  I was not able to get DSN-less ODBC connections to work.  Has anyone else had this problem?


vhari 111 posts Joined 12/08
06 Nov 2014

Can you describe the error you see with DSN-less connections ?

msirek 3 posts Joined 06/09
06 Nov 2014

Here's the error I'm getting:
Warning: odbc_connect(): SQL error: [DataDirect][ODBC lib] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in ...
Here's how I'm connecting:
$source_conn=odbc_connect("Driver=Teradata;DBCName=$SourceSystem", $SourceUserID, $SourcePassword);
I've tried different variations of this both with and without curly braces around "Teradata", and with different parameter names like ServerName in place of DBCName.
The DSN-less connection works for me on Windows (php/tdodbc/IIS 7.5), so I'm not sure what's wrong.  Here is my odbcinst.ini file with the Teradata driver defined:

vhari 111 posts Joined 12/08
06 Nov 2014

I am not a PHP expert.  The error message from PHP "SQL state IM002 in SQLConnect in" indicates it is using SQLConnect() ODBC function and this function cannot take a connection-string.
Is it the same error you see when you use "DRIVER={Teradata}" in connection-string?.  Also, try setting ODBCINST env. variable pointing to odbcinst.ini file.

msirek 3 posts Joined 06/09
06 Nov 2014

Yes, same error message with "DRIVER={Teradata}".  I did not have ODBCINST defined.  Instead I'd read that ODBCINSTINI was needed.  I've now added ODBCINST, but it's still not working.  I'll play around with it a little more.   Thanks for the help.

sankot 4 posts Joined 11/14
06 Nov 2014

Hi vhari,
When I try to run
root@> /opt/teradata/client/14.10/odbc_64/bin/tdxodbc

Enter Data Source Name: testdsn_etc
Enter UserID: admin
Enter Password:

Connecting with SQLConnect(DSN=testdsn_etc,UID=admin,PWD=*)...

.....ODBC connection successful.

ODBC version        = -03.52.0000-
DBMS name           = -Teradata-
DBMS version        = -13.10.0712
Driver name         =
Driver version      = -
Driver ODBC version = -03.51-

(type quit to terminate adhoc)
Enter SQL string : exit

'exit' command detected

ODBC connection closed.
But When I try to run from PHP
$con=odbc_connect("testdsn_etc","admin","xxxxxx") or die(odbc_errormsg()."\n\n");
my webpage is not displayed anything ..
when I try to run isql -v testdsn_etc admin password I am getting segment fault error
can You please help me out what may be the reason that I am not able to connect from PHP ..

vhari 111 posts Joined 12/08
07 Nov 2014

Sankot : Please provide error message generated from odbc_connect() call.

sankot 4 posts Joined 11/14
08 Nov 2014

I am getting memory fault(core dumped) error when I tried " isql -v testdsn_etc admin password".
But I am not getting any error messages from PHP but I do see segmentaion fault error in apache logs .

sankot 4 posts Joined 11/14
10 Nov 2014

HI Vhari,
Can you please help me in the above issue ?
FYI..This is the error I am getting when I tried isql -v dsnname userid paassword
stat("/root/.odbc.ini", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
stat("/root/.odbc.ini", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
getuid()                                = 0
stat("/root/.odbc.ini", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
stat("/root/.odbc.ini", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
getuid()                                = 0
stat("/root/.odbc.ini", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
stat("/root/.odbc.ini", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
getuid()                                = 0
stat("/root/.odbc.ini", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
stat("/root/.odbc.ini", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
getuid()                                = 0
stat("/root/.odbc.ini", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
write(2, "[ISQL]ERROR: Could not SQLConnec"..., 34[ISQL]ERROR: Could not SQLConn
) = 34
semop(1238794270, {{0, 0, 0}, {0, 1, SEM_UNDO}}, 2) = 0
semop(1238794270, {{0, -1, SEM_UNDO}}, 1) = 0
shmdt(0x7f0c53ef0000)                   = 0
exit_group(1)                           = ?

sankot 4 posts Joined 11/14
13 Nov 2014

Server Name = [testdsn_etc][length = 11 (SQL_NTS)]            
            User Name = [admin][length = 8 (SQL_NTS)]            
            Authentication = [**********][length = 10 (SQL_NTS)]
        UNICODE Using encoding ASCII 'ISO8859-1' and UNICODE 'UCS-2LE'

            Connection = 0x7f477e4fd270                
            SQLState = 0x7fffc2999090                
            Native = 0x7fffc2998e88                
            Message Text = 0x7fffc2998e90                
            Buffer Length = 511                
            Text Len Ptr = 0x7fffc2998e8e
            Handle Type = 2
            Input Handle = 0x7f477e4fd270
            Environment = 0x7f477e375010
            Handle Type = 2
            Input Handle = 0x7f477e375010
            Output Handle = 0x7f477e375600
            Connection = 0x7f477e375600            
            Server Name = [testdsn_etc][length = 11 (SQL_NTS)]            
            User Name = [kotbh001][length = 8 (SQL_NTS)]            
            Authentication = [**********][length = 10 (SQL_NTS)]
        UNICODE Using encoding ASCII 'ISO8859-1' and UNICODE 'UCS-2LE'

            Connection = 0x7f477e375600                
            SQLState = 0x7fffc2999090                
            Native = 0x7fffc2998e88                
            Message Text = 0x7fffc2998e90                
            Buffer Length = 511                
            Text Len Ptr = 0x7fffc2998e8e
            Handle Type = 2
            Input Handle = 0x7f477e375600
Can anyone help me why I am getting the above errror while connecting to teradata from PHP ?

irtizaN 2 posts Joined 09/15
28 Jun 2016

Great post on setting up PHP with Teradata. My environment is almost ready, but I'm getting the following error and it doesn't seem anyone who's posted it above has been able to resolve it.
My iSQL connectivity is working fine:

isql TDDSN-6800 <username> <password>
| Connected!                            |
|                                               |
| sql-statement                         |
| help [tablename]                    |
| quit                                         |
|                                                |
SQL> select current_date;
| Date      |
| 2016-06-28|
SQLRowCount returns 1
1 rows fetched
SQL> quit

But PHP gives this error:

Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Invalid string or buffer length, SQL state S1090 in SQLConnect

My php code:

$rs=odbc_exec($conn, "select current_date;");

Any ideas on why iSQL works but PHP isn't able to access the same DSN?


irtizaN 2 posts Joined 09/15
28 Jun 2016

Wrote the wrong error message in my post earlier: The error I'm getting is: 

Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect in...

Really appreciate it if someone can suggest a fix.

You must sign in to leave a comment.