Skip to Content.
Sympa Menu

freetds - [freetds] PHP won't return any records

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Steve Fink <sfink AT netvantix.com>
  • To: FreeTDS List <freetds AT lists.ibiblio.org>
  • Subject: [freetds] PHP won't return any records
  • Date: Mon, 29 Jun 2009 16:59:11 -0600 (MDT)

Everyone,

I have never used the PHP mssql functions before, I am versed in MySql
instead, I cannot get the following code to return any records.

The variables $dbserver, $dbuser, $dbpasswd are defined in a config file and
are being read and the connection is being made because I can change any one
of the variables to a incorrect value and mssql_connect fails.

When I use TDS Version 8.0 I get back the Resource ID # only.

<?php

$linkID = mssql_connect($dbserver, $dbuser, $dbpasswd);

if(!$linkID)
{
die('There was an error while attempting to connect to the MSSQL Server');
}

if(!$linkID || !mssql_select_db($database, $linkID))
{
die('Unable to connect or select database!');
}

//The following is for debugging
$query = "SELECT * FROM pohdr WHERE ponum = '136025'";
echo $query;

print "<BR>";
print "<BR>";

$data = mssql_query($query, $linkID) or die ('Query failed: '.$query);
$result = array();

echo $data;

do {
while ($row = mssql_fetch_row($data)){
$result[] = $row;
}
}while ( mssql_next_result($data) );

// Clean up
mssql_free_result($data);
mssql_close($linkID);

include ('common/footer.php');
?>

My environment:

Server #1 - 100% CentOS RPM installed
CentOS 5.3
Apache 2.2.3
PHP 5.1.6
FreeTDS 0.64

Server #2
Microsoft Server 2003 Enterprise Edition
SQL Server 2005
SQL Server 2000 Compatibility Tools installed

Server #3 - Compiled from Source
CentOS 5.3
Apache 2.2.11
PHP 5.2.10 (also tried 5.2.5, 5.1.6 and 4.4.7)
FreeTDS 0.82

By setting the TDS Version to 8.0 on either Server #1 or Server #2 I can make
a connection to the SQL Server using tsql -S {servername} -U {username} and
execute the SQL Query above and the records are returned.

If I set the TDS Version to 9.0 I can make a connection to the SQL server but
from 0.64 I get this error "Msg 4004, Level 16, State 1, Server {servername},
Line 1 Unicode data in a Unicode-only collation or ntext data cannot be sent
to clients using DB-Library (such as ISQL) or ODBC version 3.7 or earlier."
when I use the SQL Query above.

>From 0.82 I cannot connect to the server using tsql and I get this error
>"Msg 18456, Level 14, State 1, Server VC_SQL1, Line 1 Login failed for user
>'wrtms'. Msg 20002, Level 9, State -1, Server OpenClient, Line -1 Adaptive
>Server connection failed."

Any assistance would be greatly appreciated.

Best,

Steve




  • [freetds] PHP won't return any records, Steve Fink, 06/29/2009

Archive powered by MHonArc 2.6.24.

Top of Page