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 = tdata.so[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/08.01.00.02TD_ICU_DATA=/opt/teradata/tdicu/libODBCINST=/etc/odbcinst.iniGuys, 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.

Thanks

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
</Directory>

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:

<?php
putenv("ODBCINI=/opt/teradata/client/ODBC_32/odbc.ini");
putenv("ODBCINSTINI=/opt/teradata/client/ODBC_32/odbcinst.ini");
?>

Restart the server:

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

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

thanks

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/tdata.so' : /opt/teradata/client/ODBC_32/lib/tdata.so: 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/tdata.so

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:

TeraGSS_redhatlinux-i386-13.10.03.01-1.i386

TeraGSS_suselinux-x8664-13.10.03.01-1.x86_64

piom-13.10.00.05-1.noarch

cliv2-13.10.00.10-1.noarch

tdicu-13.10.00.02-1.noarch

tdodbc-13.10.00.07-1.noarch

 

unixODBC-2.2.14-11.el6.x86_64

unixODBC-2.2.14-11.el6.i686

Linux version 2.6.32-71.el6.x86_64 (mockbuild@x86-007.build.bos.redhat.com) (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:

<?php

putenv("ODBCINI=/home/ID973285/.odbc.ini");

putenv("ODBCINSTINI=/home/ID973285/.odbcinst.ini");

 

$conn=odbc_connect("dwhd","id066955","xxxx");

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

odbc_close($conn);

?>

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]
InstallDir=/opt/teradata/client/ODBC_64
Trace=0
TraceDll=/opt/teradata/client/ODBC_64/lib/odbctrac.so
TraceFile=/usr/joe/odbcusr/trace.log
TraceAutoStop=0

[ODBC Data Sources]
default=tdata.so
testdsn=tdata.so
dwhd=tdata.so

[dwhd]
Driver=/opt/teradata/client/ODBC_64/lib/tdata.so
Description=Teradata running Teradata V1R5.2
#DBCName=208.199.59.208
DBCName=dwhdcop1
LastUser=
Username=
Password=
Database=
DefaultDatabase=

 

Any help is more than welcome.

Thanks!

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 tdata.so 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:
[ODBC DRIVERS]
Teradata=Installed
[Teradata]
Driver=/opt/teradata/client/15.10/odbc_64/lib/tdata.so
APILevel=CORE
ConnectFunctions=YYY
DriverODBCVer=3.51
SQLLevel=1
 
 

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.
 
Mark

sankot 4 posts Joined 11/14
06 Nov 2014

Hi vhari,
When I try to run
root@200.25.2.12:etc> /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  13.10.07.12-
Driver name         = -tdata.so-
Driver version      = -14.10.00.00-
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 ..
Thanks

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
ect
) = 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'

[ODBC][20165][1415899070.015595][SQLConnect.c][3982]
        Exit:[SQL_ERROR]
[ODBC][20165][1415899070.015678][SQLError.c][430]
        Entry:                
            Connection = 0x7f477e4fd270                
            SQLState = 0x7fffc2999090                
            Native = 0x7fffc2998e88                
            Message Text = 0x7fffc2998e90                
            Buffer Length = 511                
            Text Len Ptr = 0x7fffc2998e8e
[ODBC][20165][1415899070.015728][SQLError.c][467]
        Exit:[SQL_NO_DATA]
[ODBC][20165][1415899070.015852][SQLFreeHandle.c][279]
        Entry:
            Handle Type = 2
            Input Handle = 0x7f477e4fd270
[ODBC][20165][1415899070.015896][SQLFreeHandle.c][330]
        Exit:[SQL_SUCCESS]
[ODBC][20163][1415899394.024436][__handles.c][450]
        Exit:[SQL_SUCCESS]
            Environment = 0x7f477e375010
[ODBC][20163][1415899394.024515][SQLAllocHandle.c][364]
        Entry:
            Handle Type = 2
            Input Handle = 0x7f477e375010
[ODBC][20163][1415899394.024558][SQLAllocHandle.c][482]
        Exit:[SQL_SUCCESS]
            Output Handle = 0x7f477e375600
[ODBC][20163][1415899394.024614][SQLConnect.c][3614]
        Entry:            
            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'

[ODBC][20163][1415899394.042664][SQLConnect.c][3982]
        Exit:[SQL_ERROR]
[ODBC][20163][1415899394.042736][SQLError.c][430]
        Entry:                
            Connection = 0x7f477e375600                
            SQLState = 0x7fffc2999090                
            Native = 0x7fffc2998e88                
            Message Text = 0x7fffc2998e90                
            Buffer Length = 511                
            Text Len Ptr = 0x7fffc2998e8e
[ODBC][20163][1415899394.042798][SQLError.c][467]
        Exit:[SQL_NO_DATA]
[ODBC][20163][1415899394.042907][SQLFreeHandle.c][279]
        Entry:
            Handle Type = 2
            Input Handle = 0x7f477e375600
[ODBC][20163][1415899394.042949][SQLFreeHandle.c][330]
        Exit:[SQL_SUCCESS]
 
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

Hi,
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:

<?
$conn=odbc_connect("TDDSN-6800","<username>","<password>");
$rs=odbc_exec($conn, "select current_date;");
odbc_close($conn);
?>

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.