Skip to Content.
Sympa Menu

freetds - [freetds] Problem connecting to SQL Server from PHP (localhost and port 4000 are used)

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Jaime Stuardo" <jstuardo AT desytec.com>
  • To: <freetds AT lists.ibiblio.org>
  • Subject: [freetds] Problem connecting to SQL Server from PHP (localhost and port 4000 are used)
  • Date: Thu, 23 Feb 2012 13:22:21 -0300

Hello. I am new to this list. I came here because of a problem I have with
FreeTDS to connect to SQL Server.



I am trying this PHP code:



$dbh = new PDO("dblib:desytecSQL:1433;dbname=CONTRATOS_AGD",

"$username",

"$password"

);



I got 2 problems I saw in/tmp/freetds.log file:



. The driver is trying to connect to localhost

. The driver is trying to connect to port 4000



I solved he port problem by setting the environment variable (as a patch
really, because the connection is correctly configured to use port 1433)



I don't know where FreeTDS is extracting the server localhost. I am running
the test PHP page under root account.



This is the /usr/local/etc/freetds.conf file. My connection is called:
"desytecSQL"



# $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

[desytecSQL]

#host = 10.10.20.171

host = OFICINA-DESYTEC

port = 1433

tds version = 7.2



This is my /usr/local/etc/odbc.ini file:



[ODBC Data Sources]

desytecSQL = MS SQL Server



[desytecSQL]

Driver = FreeTDS

Description = MS SQL Server

Server = OFICINA-DESYTEC

Database = CONTRATOS_AGD

User = sa

Password = N1C0kr02004

port = 1433

TDS_Version = 7.2



And finally, this is my /usr/local/etc/odbcinst.ini



[FreeTDS]

Driver=/usr/local/lib/libtdsodbc.so

Threading=1

UsageCount=2



This is what

log.c:196:Starting log file for FreeTDS 0.91

on 2012-02-23 12:45:05 with debug flags 0x4fff.

config.c:714:Setting 'dump_file' to '/tmp/freetds.log' from $TDSDUMP.

config.c:725:Setting 'port' to 1433 from $TDSPORT.

iconv.c:330:tds_iconv_open(0xa311af0, UTF-8)

iconv.c:187:local name for ISO-8859-1 is ISO-8859-1

iconv.c:187:local name for UTF-8 is UTF-8

iconv.c:187:local name for UCS-2LE is UCS-2LE

iconv.c:187:local name for UCS-2BE is UCS-2BE

iconv.c:349:setting up conversions for client charset "UTF-8"

iconv.c:351:preparing iconv for "UTF-8" <-> "UCS-2LE" conversion

iconv.c:391:preparing iconv for "ISO-8859-1" <-> "ISO-8859-1" conversion

iconv.c:394:tds_iconv_open: done

net.c:205:Connecting to 127.0.0.1 port 1433 (TDS version 5.0)

net.c:270:tds_open_socket: connect(2) returned "Operation now in progress"

net.c:306:getsockopt(2) reported: Connection refused

net.c:316:tds_open_socket() failed

util.c:331:tdserror(0xa1acf68, 0xa311af0, 20009, 111)

dblib.c:7929:dbperror(0xa311938, 20009, 111)

dblib.c:7981:20009: "Unable to connect: Adaptive Server is unavailable or
does $

dblib.c:5780:dbgetuserdata(0xa311938)

dblib.c:8002:"Unable to connect: Adaptive Server is unavailable or does not
exi$

util.c:361:tdserror: client library returned TDS_INT_CANCEL(2)

util.c:384:tdserror: returning TDS_INT_CANCEL(2)

dblib.c:1443:dbclose(0xa311938)

dblib.c:258:dblib_del_connection(0x9a9460, 0xa311af0)

mem.c:615:tds_free_all_results()

dblib.c:305:dblib_release_tds_ctx(1)

dblib.c:5882:dbfreebuf(0xa311938)

dblib.c:739:dbloginfree(0xa311290)

dblib.c:1512:dbexit(void)

dblib.c:1512:dbexit(void)

dblib.c:305:dblib_release_tds_ctx(1)

^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^$

mem.c:615:tds_free_all_results()

util.c:156:Changed query state from IDLE to DEAD

odbc.c:4040:SQLFreeConnect(0xa314d48)

odbc.c:4006:_SQLFreeConnect(0xa314d48)

odbc.c:4063:SQLFreeEnv(0xa314be8)

odbc.c:4050:_SQLFreeEnv(0xa314be8)





By the way, OFICINA-DESYTEC host does respond:



[root@Linux etc]# ping oficina-desytec

PING OFICINA-DESYTEC (192.168.2.9) 56(84) bytes of data.

64 bytes from OFICINA-DESYTEC (192.168.2.9): icmp_seq=1 ttl=128 time=0.284
ms

64 bytes from OFICINA-DESYTEC (192.168.2.9): icmp_seq=2 ttl=128 time=0.268
ms

64 bytes from OFICINA-DESYTEC (192.168.2.9): icmp_seq=3 ttl=128 time=0.297
ms

64 bytes from OFICINA-DESYTEC (192.168.2.9): icmp_seq=4 ttl=128 time=0.275
ms



Any help will be greatly appreciated,



Thanks

Jaime




  • [freetds] Problem connecting to SQL Server from PHP (localhost and port 4000 are used), Jaime Stuardo, 02/23/2012

Archive powered by MHonArc 2.6.24.

Top of Page