Centos + Apache HTTPD + PHP + ODBC

Como configurar ODBCs en Centos.

Fuentes:
http://createchperu.blogspot.com/2013/02/linux-centos-apache-php-mssqlserver.html
http://www.petri.co.il/how-to-connect-centos-web-server-to-a-sql-server.htm
http://www.easysoft.com/developer/languages/php/sql_server_unix_tutorial.html
http://stackoverflow.com/questions/16925825/having-troubles-with-unixodbc-freetds-and-pyodbc



Install FreeTDS:
# wget ftp://ftp.astron.com/pub/freetds/stable/freetds-stable.tgz
# tar -zxvf /usr/local/soft/freetds-stable.tgz
# cd /usr/local/soft/freetds-0.91
# ./configure --with-tdsver=7.0
# make
# make install

Test:
# tsql -S 10.24.1.21,1434 -U sa

Verificamos si tenemos paquetes necesarios:
#yum list freetds*
Available Packages
freetds.i386                             0.64-11.el5.centos     extras
freetds-devel.i386                       0.64-11.el5.centos     extras
freetds-doc.i386                         0.64-11.el5.centos     extras

#yum list unixodbc*
unixODBC.i386                            2.2.11-7.1             installed
Available Packages
unixODBC.i386                            2.2.11-10.el5          base
unixODBC-devel.i386                      2.2.11-10.el5          base
unixODBC-kde.i386                        2.2.11-10.el5          base
unixODBC-libs.i386                       2.2.11-10.el5          base
unixODBC64.i386                          2.2.14-3.el5           base
unixODBC64-devel.i386                    2.2.14-3.el5           base
unixODBC64-libs.i386                     2.2.14-3.el5           base

Archivos claves de la configuración del ODBC.
# vi /etc/odbc.ini
# Define a connection to a Microsoft SQL server
# The Description can be whatever we want it to be.
# The Driver value must match what we have defined in /etc/odbcinst.ini
# The Database name must be the name of the database this connection will connect to.
# The ServerName is the name we defined in /etc/freetds/freetds.conf
# The TDS_Version should match what we defined in /etc/freetds/freetds.conf

[SIC_COL_SIST]
Description = SIC_COL_SIST
Driver = DriverMSSQL
Database = BASE1
ServerName = MSSQL_SICAR
TDS_Version = 8.0

[SIC_COLO_KON]
Description = SIC_COLO_KON
Driver = DriverMSSQL
Database = BASE2
ServerName = MSSQL_SICAR
TDS_Version = 8.0
client charset = UTF-8



# vi /etc/odbcinst.ini
# Example driver definitions

# Driver from the postgresql-odbc package
# Setup from the unixODBC package
[PostgreSQL]
Description     = ODBC for PostgreSQL
Driver          = /usr/lib/psqlodbc.so
Setup           = /usr/lib/libodbcpsqlS.so
Driver64        = /usr/lib64/psqlodbc.so
Setup64         = /usr/lib64/libodbcpsqlS.so
FileUsage       = 1


# Driver from the mysql-connector-odbc package
# Setup from the unixODBC package
[MySQL]
Description     = ODBC for MySQL
Driver          = /usr/lib/libmyodbc5.so
Setup           = /usr/lib/libodbcmyS.so
Driver64        = /usr/lib64/libmyodbc5.so
Setup64         = /usr/lib64/libodbcmyS.so
FileUsage       = 1


# Drviver de MSQLSERVER
[DriverMSSQL]
Description  = MS SQL database access with Free TDS
Driver  = /usr/local/lib/libtdsodbc.so
Setup  = /usr/lib64/libtdsS.so
UsageCount  = 1


[ms-sql]
Description  = TDS connection
Driver  = /usr/local/lib/libtdsodbc.so
Setup  = /usr/lib64/libtdsS.so
FileUsage  = 1
UsageCount  = 1

# Change the "no" to "yes" to enable ODBC logging.
[ODBC]
Trace           = yes
TraceFile       = /tmp/odbc.log




# vi /usr/local/etc/freetds.conf
#   $Id: freetds.conf,v 1.12 2007/12/25 06:02:36 jklowden Exp $
#
# This file is installed by FreeTDS if no file by the same
# name is found in the installation directory.
#
# For information about the layout of this file and its settings,
# see the freetds.conf manpage "man freetds.conf".

# Global settings are overridden by those in a database
# server specific section
[global]
        # TDS protocol version
;       tds version = 4.2

        # Whether to write a TDSDUMP file for diagnostic purposes
        # (setting this to /tmp is insecure on a multi-user system)
;       dump file = /tmp/freetds.log
;       debug flags = 0xffff

        # Command and connection timeouts
;       timeout = 10
;       connect timeout = 10

        # If you get out-of-memory errors, it may mean that your client
        # is trying to allocate a huge buffer for a TEXT field.
        # Try setting 'text size' to a more reasonable limit
        text size = 64512

# A typical Sybase server
[egServer50]
        host = symachine.domain.com
        port = 5000
        tds version = 5.0

# A typical Microsoft server
[egServer70]
        host = ntmachine.domain.com
        port = 1433
        tds version = 7.0

# MSSQL SIC
[MSSQL_SIC]
        host = 192.168.1.21
        port = 1434
        tds version = 7.4


en el prompt de la linea de comandos probamos la conexión

# isql -v odbc-test sa mipassword

y nos arrojara el siguiente resultado

+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL>

probamos query
SQL> select * from Customers



















Comentarios

Entradas populares