Skip to Content.
Sympa Menu

freetds - Re: [freetds] SP input parameter problem on 0.63

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "ZIGLIO, Frediano, VF-IT" <Frediano.Ziglio AT vodafone.com>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Cc: "Frank M. Kromann" <frank AT kromann.info>
  • Subject: Re: [freetds] SP input parameter problem on 0.63
  • Date: Tue, 9 Aug 2005 11:32:14 +0200

>
> Hi Freddy,
>
> I'm trying to solve http://bugs.php.net/bug.php?id=29316 too.
> As far as I
> can tell this is an issue in FreeTDS too. I'm using 0.64-dev
> from cvs and
> I'm caling a SP that returns two results. First result does
> not have any
> rows. On my windows box the code returns both results but it
> looks like
> FreeTDS is skipping the first result.
>
> The code:
> create procedure a_test as
> select * from t1 where 1=2
> select * from t1
>
> The php code:
>
>
> <?php
> if (!extension_loaded("mssql"))
> {
> dl("php_mssql." . PHP_SHLIB_SUFFIX);
> }
>
> $host = "64.186.239.115";
> $user = "web";
> $password = "webuser";
> $database = "Swwwing2000";
>
> $con = mssql_connect($host, $user, $password);
> if ($con) {
> if (mssql_select_db($database, $con)) {
> $stmt = mssql_init("a_test", $con);
> $rs = mssql_execute($stmt);
> if (is_resource($rs)) {
> echo "fetching...\n";
> $i = 1;
> do {
> echo "Processing result $i\n";
> echo "Num rows = " .
> mssql_num_rows($rs) . "\n";
> // Process result
> $i++;
> } while (mssql_next_result($rs));
> mssql_free_result($rs);
> }
> }
> mssql_close($con);
> }
> ?>
>
> The result on Windows:
> fetching...
> Processing result 1
> Num rows = 0
> Processing result 2
> Num rows = 222
>
> The result on Linux with FreeTDS:
> fetching...
> Processing result 1
> Num rows = 222
>

0.63 (with post fixes) and 0.64 work much better

I tried this script

<?php
$conn = mssql_connect("testhost","test","test") or die("opps");

mssql_query("if exists (select * from sysobjects where name =
'php_test') drop table php_test", $conn);
mssql_query("if exists (select * from sysobjects where name =
'sp_php_test') drop proc sp_php_test", $conn);
mssql_query("create table php_test(id int, c varchar(20))", $conn) or
die("creating table");

mssql_query("insert into php_test values(1, 'aaa')", $conn) or
die("inserting data");
mssql_query("insert into php_test values(10, 'meeewww')", $conn) or
die("inserting data");

$sql = <<<EOSQL
CREATE PROCEDURE sp_php_test AS
-- first Query: no match
SELECT * FROM php_test WHERE id=10000
-- second Query: 2 matches
SELECT * FROM php_test
EOSQL;

mssql_query($sql, $conn) or die("error querying");

# one time to let sql compile and compute statistics on table
$rs = mssql_query("sp_php_test", $conn) or die("error querying");
mssql_next_result($rs);
mssql_next_result($rs);
mssql_free_result($rs);

$stmt = mssql_init("sp_php_test", $conn);
$rs = mssql_execute($stmt);
if (is_resource($rs)) {
echo "fetching...\n";
$i = 1;
do {
echo "Processing result $i\n";
echo "Num rows = " . mssql_num_rows($rs) . "\n";
// Process result
++$i;
} while (mssql_next_result($rs));
mssql_free_result($rs);
}

# cleanup
mssql_query("drop proc sp_php_test");
mssql_query("drop table php_test");

mssql_close($conn);
?>

and give

fetching...
Processing result 1
Num rows = 0
Processing result 2
Num rows = 2
Processing result 3
Num rows = 0

Well, an additional false recordset but first two are correct.

freddy77




Archive powered by MHonArc 2.6.24.

Top of Page