[unixODBC-support] FreeTDS w/ unixODBC, PHP and Apache

Stefan Radman Stefan.Radman at CTBTO.ORG
Tue Mar 11 10:47:35 GMT 2008


The problem you describe is usually caused by differing environments:
root shell vs Apache process.
Ensure that your Apache process is using the same unixODBC binaries and
configuration files as the root shell executing php.
Executing "odbcinst -j"  in both environments might shed more light on
the issue.
 
Stefan


  _____  

	From: unixodbc-support-bounces at easysoft.com
[mailto:unixodbc-support-bounces at easysoft.com] On Behalf Of Nelson Neves
Marques
	Sent: Tuesday, 11 March, 2008 10:33
	To: unixodbc-support at easysoft.com
	Subject: [unixODBC-support] FreeTDS w/ unixODBC, PHP and Apache
	
	

	Hello,

	 

	I'm currently trying to configure FreeTDS with unixODBC, PHP and
Apache.

	 

	I'm using the 0.64 version and it works fine for PHP in the
command line. However, when I try to run the same file on Apache it
doesn't connect to the database.

	 

	Can you help me with this issue. Below are both scenarios with
the respective odbc trace files.

	 

	Thanks,

	 

	Nelson Marques

	 

	 

	
########################################################################
############

	 

	[root at localhost html]# cat /etc/odbc.ini

	[MSSQLTestServer]

	Driver          = FreeTDS

	Description     = Zend Framework DB

	Trace           = No

	Server          = 192.168.35.1

	Port            = 1433

	Database        = ZendFramework

	TDS_Version     = 8.0

	 

	
########################################################################
############

	 

	[root at localhost html]# cat /etc/odbcinst.ini

	[FreeTDS]

	Description     = v0.64 with protocol v8.0

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

	UsageCount      = 1

	 

	[ODBC]

	TraceFile = /tmp/sql.log

	Trace = Yes

	 

	
########################################################################
############

	[root at localhost html]# cat /var/www/html/test.php

	<?php

	$connect = odbc_connect("MSSQLTestServer", "sa", "sa123");

	 

	$query = "SELECT * FROM xpto";

	 

	$result = odbc_exec($connect, $query);

	while(odbc_fetch_row($result)) {

	$field1 = odbc_result($result, 1);

	$field2 = odbc_result($result, 2);

	print("$field1 $field2\n");

	}

	odbc_close($connect);

	?>

	 

	
########################################################################
############

	 

	[root at localhost html]# php test.php

	1 a

	2 b

	3 c

	 

	
########################################################################
############

	 

	[root at localhost html]# cat /tmp/sql.log

	[ODBC][2878][__handles.c][444]

	                Exit:[SQL_SUCCESS]

	                        Environment = 0x9160ef0

	[ODBC][2878][SQLAllocHandle.c][345]

	                Entry:

	                        Handle Type = 2

	                        Input Handle = 0x9160ef0

	[ODBC][2878][SQLAllocHandle.c][463]

	                Exit:[SQL_SUCCESS]

	                        Output Handle = 0x915c1c8

	[ODBC][2878][SQLConnect.c][3549]

	                Entry:

	                        Connection = 0x915c1c8

	                        Server Name = [MSSQLTestServer][length =
15 (SQL_NTS)]

	                        User Name = [sa][length = 2 (SQL_NTS)]

	                        Authentication = [*****][length = 5
(SQL_NTS)]

	                UNICODE Using encoding ASCII 'ISO8859-1' and
UNICODE 'UCS-2LE'

	 

	[ODBC][2878][SQLConnect.c][4123]

	                Exit:[SQL_SUCCESS]

	 

	...

	 

	 

	
########################################################################
############

	 

	[root at localhost html]# wget http://localhost/test.php

	 

	
########################################################################
############

	 

	[root at localhost html]# cat /tmp/sql.log

	[ODBC][2804][__handles.c][444]

	                Exit:[SQL_SUCCESS]

	                        Environment = 0x942f4d0

	[ODBC][2804][SQLAllocHandle.c][345]

	                Entry:

	                        Handle Type = 2

	                        Input Handle = 0x942f4d0

	[ODBC][2804][SQLAllocHandle.c][463]

	                Exit:[SQL_SUCCESS]

	                        Output Handle = 0x942ce48

	[ODBC][2804][SQLConnect.c][3549]

	                Entry:

	                        Connection = 0x942ce48

	                        Server Name = [MSSQLTestServer][length =
15 (SQL_NTS)]

	                        User Name = [sa][length = 2 (SQL_NTS)]

	                        Authentication = [*****][length = 5
(SQL_NTS)]

	                UNICODE Using encoding ASCII 'ISO8859-1' and
UNICODE 'UCS-2LE'

	 

	                DIAG [08S01] [FreeTDS][SQL Server]Server is
unavailable or does not exist.

	 

	                DIAG [S1000] [FreeTDS][SQL Server]Unable to
connect to data source

	 

	[ODBC][2804][SQLConnect.c][3917]

	                Exit:[SQL_ERROR]

	[ODBC][2804][SQLError.c][424]

	                Entry:

	                        Connection = 0x942ce48

	                        SQLState = 0xbfb11242

	                        Native = 0xbfb1103c

	                        Message Text = 0xbfb11042

	                        Buffer Length = 511

	                        Text Len Ptr = 0xbfb11040

	[ODBC][2804][SQLError.c][461]

	                Exit:[SQL_SUCCESS]

	                        SQLState = S1000

	                        Native = 0xbfb1103c -> 0

	                        Message Text = [[unixODBC][FreeTDS][SQL
Server]Unable to connect to data source]

	[ODBC][2804][SQLFreeHandle.c][268]

	                Entry:

	                        Handle Type = 2

	                        Input Handle = 0x942ce48

	[ODBC][2804][SQLFreeHandle.c][317]

	                Exit:[SQL_SUCCESS]

	 

	 

	 

	 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.unixodbc.org/pipermail/unixodbc-support/attachments/20080311/5c41d115/attachment.html>


More information about the unixODBC-support mailing list