[freetds] SQL error during odbc_connect in PHP using FreeTDS

stanislav puffler stanislav.puffler at eficia.cz
Wed Jan 4 08:27:09 EST 2006


Hi,
have installed FreeTDS (freetds_mssql0 packages - 0.64 and unixODBC) into my Linux Box (Mandriva 2006 free) and want to use it on my intranet (Apache, PHP) to connect to remote host with MS SQL Server 2000 running on Windows 2000 Server.
TSQL utility is succesful without problem.

------------------------------------------------------------------
[puffler at blackmarket ~]$ tsql_mssql -S solidus -U user -P password
locale is "cs_CZ"
locale charset is "ISO-8859-2"
1>
------------------------------------------------------------------

So I have installed php-odbc package and unixODBC. Also configuration of DSN was succesful, because of :

------------------------------------------------------------------
[puffler at blackmarket ~]$ isql nextccdb user password
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL>
------------------------------------------------------------------

Here is my configuration in /etc :

1) freetds_mssql.conf

[solidus]
        host = solidus.eficia.cz
        port = 1433
        tds version = 7.0
        client charset = ISO-8859-2

2) odbc.ini

[nextccdb]
Description             = MSSQLServer
Driver          = MSSQLServer
Servername              = solidus
Server          = solidus.eficia.cz
Address         = 192.168.0.10
Port            = 1433
Database                = nextccdb
TDS_Version             = 8.0
Language                = us_english
TextSize                =
Domain          = eficia.cz
PacketSize              =

But the only one problem is when I want to finish my mission and connect to MS SQL via PHP script and odbc_connect function from intranet, I get an error. The script is like this :

------------------------------------------------------------------
<?php
// connect to DSN MSSQL with a user and password
$connect = odbc_connect("nextccdb", "user", "password") or die
  ("couldn't connect");
odbc_exec($connect, "use kk_c_code");
$result = odbc_exec($connect, "SELECT name, active " .
        "FROM kk_c_code");
while(odbc_fetch_row($result)){
  print(odbc_result($result, "name") .
        ' ' . odbc_result($result, "active") . "<br>\n");
}
odbc_free_result($result);
odbc_close($connect);
?>
------------------------------------------------------------------

Here is what I get - after about 15 seconds of script running, it is timed out with this :

------------------------------------------------------------------
Warning: odbc_connect() [function.odbc-connect]: SQL error: Unexpected protocol character during authentication; Error while reading from the socket., SQL state 28000 in SQLConnect in /var/www/html/vytaceni/mssql.php on line 3
couldn't connect
------------------------------------------------------------------

What do I need to change for succesful connection ? Thanks a lot for your suggestion. Best regards,

Stanislav Puffler
IT Specialist - Eficia Praha spol. s r.o.


More information about the FreeTDS mailing list