I have been working this week on configuring a Linux server to connect to Oracle and Sybase using unixODBC to be used by a System running on PHP.
So, I thought of sharing my /etc/odbc.ini and /etc/odbcinst.ini since I had a bit of hard time writing them. It may help someone who is trying to figure out how to connect using ODBC on Linux.
Packages Required on CentOS
httpd php unixODBC
Manually Install Oracle Instant Client 11.1 RPM Packages and Install Sybase ASE from the TGZ File.
For Oracle you need to copy all the libs to /usr/lib
cp /usr/lib/oracle/11.1/client/lib /usr/lib/
/usr/lib/oracle/11.1/client/lib
/etc/odbcinst.ini Contents:
[Oracle] Description = Oracle ODBC Connection Driver = /usr/lib/oracle/11.1/client/lib/libsqora.so.11.1 Setup = FileUsage = CPTimeout = CPReuse =
[Sybase] Description = Sybase ODBC Driver Driver = /opt/sybase/DataAccess/ODBC/lib/libsybdrvodb.so FileUsage = -1
/etc/odbc.ini Contents:
[Oracle] Application Attributes = T Attributes = W BatchAutocommitMode = IfAllSuccessful CloseCursor = F DisableDPM = F DisableMTS = T Driver = Oracle EXECSchemaOpt = EXECSyntax = T Failover = T FailoverDelay = 10 FailoverRetryCount = 10 FetchBufferSize = 64000 ForceWCHAR = F Lobs = T Longs = T MetadataIdDefault = F QueryTimeout = T ResultSets = T ServerName = //serverip:port/dbname SQLGetData extensions = F Translation DLL = Translation Option = 0 UserID =
[Sybase] Driver = Sybase Server = serverip Port = serverport Database = dbname
PHP Script to Test ODBC Connectivity:
<?php $query = "select \* from table\_name"; $conn = odbc\_pconnect("DSN", "username", "password"); if(!$conn) die("Connection failed"); if($result = odbc\_exec($conn, $query)) { echo "Query returned : " . odbc\_num\_rows($result) . "rows"; odbc\_result\_all($result); } ?>