#35884 [Asn]: mssql connection is lost after mssql_query (with bigint)

2006-01-03 Thread muratyaman at gmail dot com
 ID:   35884
 User updated by:  muratyaman at gmail dot com
 Reported By:  muratyaman at gmail dot com
 Status:   Assigned
 Bug Type: MSSQL related
 Operating System: Win XP Pro SP2
 PHP Version:  5.1.2RC1
 Assigned To:  fmk
 New Comment:

Sorry, my comments in PHP code before running the 1st query might be
misleading (forgot to modify during submission to here). Discard them
and please refer to the explanation.
Thanks.


Previous Comments:


[2006-01-03 16:19:55] [EMAIL PROTECTED]

Assigned to the maintainer.



[2006-01-03 16:17:39] muratyaman at gmail dot com

Description:

Hi,
I am disappointed about the way PHP communicates with MS SQL Server and
handles queries. I costed me more than a week to find out this.
Basically, it is related to BIGINT data types, I guess.
Here is the test case:
Have a simple table including a field of type bigint.
Have a procedure reading data from it, returning an output field of
type bigint and a resultset on the fly.
Have a simple SQL statement to declare a temp variable of type bigint,
calling this procedure and getting the output.
Use this through mssql_query() function.
Have another simle select query.
I expect 2 resultsets from the 1st query (2 values output) and another
from the 2nd query.
But I have 1 resultset from the 1st query (1 value)
and a failure for a correct SQL statement.
Because it is understood that connection is lost somehow during the 1st
query without any error message.
If you change every BIGINT to INT it works fine.
However, I do NOT think this is the solution.

Reproduce code:
---
--sql statements to prepare database

CREATE TABLE [T1] (
  [id] bigint NOT NULL,
  [name] nvarchar(50) NOT NULL,
  PRIMARY KEY CLUSTERED ([id])
)
GO

INSERT INTO [T1] ([id], [name])
VALUES 
  (1, 'abc')
GO

INSERT INTO [T1] ([id], [name])
VALUES 
  (2, 'def')
GO

CREATE PROCEDURE my_proc
   @output1 bigint output
AS
BEGIN
  --set the value
  select top 1
@output1 = id
  from  t1

  --return recordset for php
  select @output1 as MY_BIG_INT_output1
  
END
GO

--end of sql


';
  if(mssql_select_db('mydb')){
 echo 'Database selected!';

 $input1=2;
 $sql ="
  DECLARE @o BIGINT
  EXECUTE my_proc @o output
  SELECT @o as output2
  "
 ;
 echo 'Running SQL:'.$sql.''; 
 //if there is an emp record 
 //  there will be 3 result sets: emp, return_value, output1
 //else
 //  there will be 2 result sets: return_value, output1
 if($rs = mssql_query($sql)){
do{
  while($row = mssql_fetch_assoc($rs)){
  echo ''.print_r($row,true).'';
  }
} while(mssql_next_result($rs));
mssql_free_result($rs);
 }else{
echo 'Error: '.mssql_get_last_message().'';
 }

 //try another query
 $sql2='SELECT TOP 1 * FROM t1';
 echo 'Running SQL:'.$sql2.'';
 if($rs2 = mssql_query($sql2)){
while($row2 = mssql_fetch_assoc($rs2)){
  echo ''.print_r($row2,true).'';
}
mssql_free_result($rs2);
 }else{
echo 'Error: '.mssql_get_last_message().'';
 }
  }else{
echo 'Database selection failed!';
  }//end if select db
  mssql_close($dbh);
}else{
  echo 'Host connection failed!';
}//end if connection

//end of PHP file
?>

Expected result:

Host connected
Database selected!
Running SQL:

  DECLARE @o bigint
  EXECUTE my_proc @o output
  SELECT @o as output2
  
Array
(
[MY_BIG_INT_output1] => 1
)

Array
(
[output2] => 1
)

Running SQL:

SELECT TOP 1 * FROM t1
Array
(
[id] => 1
[name] => abc
)

 or an error message/warning if a particular datatype is not
supported, etc.


Actual result:
--
Host connected
Database selected!
Running SQL:

  DECLARE @o bigint
  EXECUTE my_proc @o output
  SELECT @o as output2
  
Array
(
[MY_BIG_INT_output1] => 1
)

Running SQL:

SELECT TOP 1 * FROM t1

Warning: mssql_query() [function.mssql-query]: Unable to set query in
...test_proc.php on line 34
Error: 






-- 
Edit this bug report at http://bugs.php.net/?id=35884&edit=1


#35884 [NEW]: mssql connection is lost after mssql_query (with bigint)

2006-01-03 Thread muratyaman at gmail dot com
From: muratyaman at gmail dot com
Operating system: Win XP Pro SP2
PHP version:  5.1.2RC1
PHP Bug Type: MSSQL related
Bug description:  mssql connection is lost after mssql_query (with bigint)

Description:

Hi,
I am disappointed about the way PHP communicates with MS SQL Server and
handles queries. I costed me more than a week to find out this. Basically,
it is related to BIGINT data types, I guess.
Here is the test case:
Have a simple table including a field of type bigint.
Have a procedure reading data from it, returning an output field of type
bigint and a resultset on the fly.
Have a simple SQL statement to declare a temp variable of type bigint,
calling this procedure and getting the output.
Use this through mssql_query() function.
Have another simle select query.
I expect 2 resultsets from the 1st query (2 values output) and another
from the 2nd query.
But I have 1 resultset from the 1st query (1 value)
and a failure for a correct SQL statement.
Because it is understood that connection is lost somehow during the 1st
query without any error message.
If you change every BIGINT to INT it works fine.
However, I do NOT think this is the solution.

Reproduce code:
---
--sql statements to prepare database

CREATE TABLE [T1] (
  [id] bigint NOT NULL,
  [name] nvarchar(50) NOT NULL,
  PRIMARY KEY CLUSTERED ([id])
)
GO

INSERT INTO [T1] ([id], [name])
VALUES 
  (1, 'abc')
GO

INSERT INTO [T1] ([id], [name])
VALUES 
  (2, 'def')
GO

CREATE PROCEDURE my_proc
   @output1 bigint output
AS
BEGIN
  --set the value
  select top 1
@output1 = id
  from  t1

  --return recordset for php
  select @output1 as MY_BIG_INT_output1
  
END
GO

--end of sql


';
  if(mssql_select_db('mydb')){
 echo 'Database selected!';

 $input1=2;
 $sql ="
  DECLARE @o BIGINT
  EXECUTE my_proc @o output
  SELECT @o as output2
  "
 ;
 echo 'Running SQL:'.$sql.''; 
 //if there is an emp record 
 //  there will be 3 result sets: emp, return_value, output1
 //else
 //  there will be 2 result sets: return_value, output1
 if($rs = mssql_query($sql)){
do{
  while($row = mssql_fetch_assoc($rs)){
  echo ''.print_r($row,true).'';
  }
} while(mssql_next_result($rs));
mssql_free_result($rs);
 }else{
echo 'Error: '.mssql_get_last_message().'';
 }

 //try another query
 $sql2='SELECT TOP 1 * FROM t1';
 echo 'Running SQL:'.$sql2.'';
 if($rs2 = mssql_query($sql2)){
while($row2 = mssql_fetch_assoc($rs2)){
  echo ''.print_r($row2,true).'';
}
mssql_free_result($rs2);
 }else{
echo 'Error: '.mssql_get_last_message().'';
 }
  }else{
echo 'Database selection failed!';
  }//end if select db
  mssql_close($dbh);
}else{
  echo 'Host connection failed!';
}//end if connection

//end of PHP file
?>

Expected result:

Host connected
Database selected!
Running SQL:

  DECLARE @o bigint
  EXECUTE my_proc @o output
  SELECT @o as output2
  
Array
(
[MY_BIG_INT_output1] => 1
)

Array
(
[output2] => 1
)

Running SQL:

SELECT TOP 1 * FROM t1
Array
(
[id] => 1
[name] => abc
)

 or an error message/warning if a particular datatype is not
supported, etc.


Actual result:
--
Host connected
Database selected!
Running SQL:

  DECLARE @o bigint
  EXECUTE my_proc @o output
  SELECT @o as output2
  
Array
(
[MY_BIG_INT_output1] => 1
)

Running SQL:

SELECT TOP 1 * FROM t1

Warning: mssql_query() [function.mssql-query]: Unable to set query in
...test_proc.php on line 34
Error: 


-- 
Edit bug report at http://bugs.php.net/?id=35884&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=35884&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): 
http://bugs.php.net/fix.php?id=35884&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=35884&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=35884&r=fixedcvs
Fixed in release: 
http://bugs.php.net/fix.php?id=35884&r=alreadyfixed
Need backtrace:   http://bugs.php.net/fix.php?id=35884&r=needtrace
Need Reproduce Script:http://bugs.php.net/fix.php?id=35884&r=needscript
Try newer version:http://bugs.php.net/fix.php?id=35884&r=oldversion
Not developer issue:  http://bugs.php.net/fix.php?id=35884&r=support
Expected behavior:http://bugs.php.net/fix.php?id=35884&r=notwrong
Not enough info:  
http://bugs.php.net/fix.php?id=35884&r=notenoughinfo
Submitted twice: 

#35839 [Bgs]: mssql_query(): "Possible network error: Bad token from SQL Server.."

2005-12-29 Thread muratyaman at gmail dot com
 ID:   35839
 User updated by:  muratyaman at gmail dot com
 Reported By:  muratyaman at gmail dot com
 Status:   Bogus
 Bug Type: MSSQL related
 Operating System: Win XP Pro SP2
 PHP Version:  5CVS-2005-12-29 (snap)
 Assigned To:  fmk
 New Comment:

Thank you very much indeed, at least you directed me to a solution..

Previous version of my function was already using mssql_query and fetch
functions to get the row returned from my procedure (since inside
procedure I have: 
"select @id as ID" it returns a resultset), not the output or return
code:

DECLARE @MY_ID INT8, @r int8
EXECUTE @r= SPMY_GET_NEXT_ID \"$mygenid\", @MY_ID OUTPUT

and it was doing it all right, but subsequent calls to the db was
causing the error I mentioned, because the connection is somehow lost
after running this sql.

If you think this is not a bug you can close it.
Your prompt replies are much appreciated.
Kind regards


Previous Comments:


[2005-12-30 00:49:20] [EMAIL PROTECTED]

using mssql_qyery() to execute storred procedures is usefull, but it
can only be used to retreive result sets. output parameters and return
values are not handled with this method. In that case you must use the
mssql_init(), mssql_bind() and mssql_execute() functions.



[2005-12-30 00:46:25] [EMAIL PROTECTED]

bigint is not known on my mssql server 7 but it works fine on mssql
server 2000.

I have tested your code on both servers using PHP 5.1.2-dev and I do
not get any errors. I don't think there is any errors here.

I have also tested with both local and remote server and with
php_mssql.dll and php_dblib.dll.

----

[2005-12-30 00:21:51] muratyaman at gmail dot com

Hi again :)

I changed my function to this:

function db_get_next_id($mygenid=''){
  $id = 0; $ret_val=0;
  $stmt = mssql_init("SPMY_GET_NEXT_ID");
  mssql_bind($stmt, "@GEN_ID_NAME", &$mygenid, SQLVARCHAR,
FALSE,FALSE);//input, not null
  mssql_bind($stmt, "@ID", &$id, SQLINT4, TRUE,TRUE);//output,null
  mssql_bind($stmt,"RETVAL",&$ret_val,SQLINT4);
  $result = mssql_execute($stmt);

  while($row=mssql_fetch_row($result)){
//read id
$id=$row[0];//but it should get from the output variable!?
  }
  mssql_free_statement($stmt);
  unset($stmt);  // <---VERY important
  return $id;
}

Anyway, this solved my problem.

But will I not be able to use arbitrary SQL statements with
mssql_query, including execution of procedures, etc. ?!

Kind regards

--------------------

[2005-12-29 23:54:16] muratyaman at gmail dot com

Basically, my procedure inserts a dummy record into a special table and
gets inserted id. (int8 is a udt for 'bigint', i'm changing it for you
below to bigint).
I have dummy tables to simulate sequence generators for different
tables, here is a pair of them:

CREATE TABLE TBL_GEN_ABC_ID (
  ID bigint IDENTITY(1, 1) NOT NULL,
  DUMMY bit,
  CONSTRAINT PK_TBL_GEN_ABC_ID PRIMARY KEY CLUSTERED (ID)
)
GO
CREATE TABLE TBL_ABC (
  ABC_ID INT NOT NULL,
  ABC_NAME] VARCHAR(100) NOT NULL,
  CONSTRAINT PK_TBL_ABC PRIMARY KEY CLUSTERED (ABC_ID)
)
GO

Procedure is like this:
CREATE PROCEDURE spmy_get_next_id(
  @GEN_ID_NAME VARCHAR(100)='#NO TABLE',
  @ID bigint OUTPUT
)
AS
BEGIN

  SET @ID=NULL;
  
  DECLARE @GEN_ID bigint;
  SET @GEN_ID=0;
  
  IF (UPPER(@GEN_ID_NAME)='ABC_ID')
  BEGIN
 WHILE (1=1)
 BEGIN
 
   --generate id
   INSERT INTO TBL_GEN_ABC_ID (DUMMY)
   VALUES(0);
   SET @GEN_ID=@@IDENTITY; --get generated id

   IF(NOT EXISTS( --make sure it was not used
 SELECT ABC_ID
 FROM TBL_ABC
 WHERE [EMAIL PROTECTED])
 )
   BREAK;
 END

  END
  
  SET @[EMAIL PROTECTED]; 
  SELECT @ID AS ID;--for PHP to read resultset and value
  RETURN @ID;  --return value, not crucial
END
GO

so in PHP you can use modifed version of my function:

function db_get_next_id($mygenid=''){
  $i=0;
  $sql="
  DECLARE @MY_ID bigint, @r bigint
  EXECUTE @r=SPMY_GET_NEXT_ID \"$mygenid\", @MY_ID OUTPUT
  "
  ;
  
  if($qry=db_query($sql)){
 while($row=db_fetch_row($qry)){
 $i=$row[0]; break;
 }
 db_free_result($qry);
  }
  return $i;
}//end fun get next id

$new_id=db_get_next_id('ABC_ID');
(As I mentioned earlier, e.g. db_fetch_row is just using
mssql_fetch_row.. all of my db_xyz functions are like this.)

This works fine but subsequent mssql_query functions fail.
This may not be the ideal way of doing it, but it should not  cause any
harm. Everything else is working fine. Maybe I should just change the
way I use my procedures..

#35839 [Asn]: mssql_query(): "Possible network error: Bad token from SQL Server.."

2005-12-29 Thread muratyaman at gmail dot com
 ID:   35839
 User updated by:  muratyaman at gmail dot com
 Reported By:  muratyaman at gmail dot com
 Status:   Assigned
 Bug Type: MSSQL related
 Operating System: Win XP Pro SP2
 PHP Version:  5CVS-2005-12-29 (snap)
 Assigned To:  fmk
 New Comment:

Hi again :)

I changed my function to this:

function db_get_next_id($mygenid=''){
  $id = 0; $ret_val=0;
  $stmt = mssql_init("SPMY_GET_NEXT_ID");
  mssql_bind($stmt, "@GEN_ID_NAME", &$mygenid, SQLVARCHAR,
FALSE,FALSE);//input, not null
  mssql_bind($stmt, "@ID", &$id, SQLINT4, TRUE,TRUE);//output,null
  mssql_bind($stmt,"RETVAL",&$ret_val,SQLINT4);
  $result = mssql_execute($stmt);

  while($row=mssql_fetch_row($result)){
//read id
$id=$row[0];//but it should get from the output variable!?
  }
  mssql_free_statement($stmt);
  unset($stmt);  // <---VERY important
  return $id;
}

Anyway, this solved my problem.

But will I not be able to use arbitrary SQL statements with
mssql_query, including execution of procedures, etc. ?!

Kind regards


Previous Comments:
--------------------

[2005-12-29 23:54:16] muratyaman at gmail dot com

Basically, my procedure inserts a dummy record into a special table and
gets inserted id. (int8 is a udt for 'bigint', i'm changing it for you
below to bigint).
I have dummy tables to simulate sequence generators for different
tables, here is a pair of them:

CREATE TABLE TBL_GEN_ABC_ID (
  ID bigint IDENTITY(1, 1) NOT NULL,
  DUMMY bit,
  CONSTRAINT PK_TBL_GEN_ABC_ID PRIMARY KEY CLUSTERED (ID)
)
GO
CREATE TABLE TBL_ABC (
  ABC_ID INT NOT NULL,
  ABC_NAME] VARCHAR(100) NOT NULL,
  CONSTRAINT PK_TBL_ABC PRIMARY KEY CLUSTERED (ABC_ID)
)
GO

Procedure is like this:
CREATE PROCEDURE spmy_get_next_id(
  @GEN_ID_NAME VARCHAR(100)='#NO TABLE',
  @ID bigint OUTPUT
)
AS
BEGIN

  SET @ID=NULL;
  
  DECLARE @GEN_ID bigint;
  SET @GEN_ID=0;
  
  IF (UPPER(@GEN_ID_NAME)='ABC_ID')
  BEGIN
 WHILE (1=1)
 BEGIN
 
   --generate id
   INSERT INTO TBL_GEN_ABC_ID (DUMMY)
   VALUES(0);
   SET @GEN_ID=@@IDENTITY; --get generated id

   IF(NOT EXISTS( --make sure it was not used
 SELECT ABC_ID
 FROM TBL_ABC
 WHERE [EMAIL PROTECTED])
 )
   BREAK;
 END

  END
  
  SET @[EMAIL PROTECTED]; 
  SELECT @ID AS ID;--for PHP to read resultset and value
  RETURN @ID;  --return value, not crucial
END
GO

so in PHP you can use modifed version of my function:

function db_get_next_id($mygenid=''){
  $i=0;
  $sql="
  DECLARE @MY_ID bigint, @r bigint
  EXECUTE @r=SPMY_GET_NEXT_ID \"$mygenid\", @MY_ID OUTPUT
  "
  ;
  
  if($qry=db_query($sql)){
 while($row=db_fetch_row($qry)){
 $i=$row[0]; break;
 }
 db_free_result($qry);
  }
  return $i;
}//end fun get next id

$new_id=db_get_next_id('ABC_ID');
(As I mentioned earlier, e.g. db_fetch_row is just using
mssql_fetch_row.. all of my db_xyz functions are like this.)

This works fine but subsequent mssql_query functions fail.
This may not be the ideal way of doing it, but it should not  cause any
harm. Everything else is working fine. Maybe I should just change the
way I use my procedures..
Thank you.



[2005-12-29 22:37:33] [EMAIL PROTECTED]

Frank, can you make any sense to this? :)



[2005-12-29 22:35:42] muratyaman at gmail dot com

Thank you.
I could not integrate php_dblib.dll :(
I tried to compile FreeTDS using Dev-C++ but could not get it working
with PHP.. I am stuck.

I was investigating the problem.
I have a function as follows:

function db_get_next_id($mygenid=''){
  $i=0;
  $sql="
  DECLARE @MY_ID INT8, @r int8
  EXECUTE @r= SPMY_GET_NEXT_ID \"$mygenid\", @MY_ID OUTPUT
  "
  ;
  
  if($qry=db_query($sql)){
 while($row=db_fetch_row($qry)){
 $i=$row[0]; break;
 }
 db_free_result($qry);
  }
  return $i;
}//end fun get next id

$new_id=db_get_next_id('keyfield');

This just works fine, I found that after this, calls to the db fails
and produces the error. Because when I comment out the line calling
this function, I don't get any error message.
Any ideas?
Regards



[2005-12-29 22:15:50] [EMAIL PROTECTED]

Does using php_dblib.dll work any better or not?



[2005-12-29 17:36:44] muratyaman at gmail dot com

Hi!
I installed latest version of PHP (5.1.2rc2) but same :(
I found out that even the simplest of my pages have same problem
regardless of combobox.
My db abstraction layer is really simpl

#35839 [Asn]: mssql_query(): "Possible network error: Bad token from SQL Server.."

2005-12-29 Thread muratyaman at gmail dot com
 ID:   35839
 User updated by:  muratyaman at gmail dot com
 Reported By:  muratyaman at gmail dot com
 Status:   Assigned
 Bug Type: MSSQL related
 Operating System: Win XP Pro SP2
 PHP Version:  5CVS-2005-12-29 (snap)
 Assigned To:  fmk
 New Comment:

Basically, my procedure inserts a dummy record into a special table and
gets inserted id. (int8 is a udt for 'bigint', i'm changing it for you
below to bigint).
I have dummy tables to simulate sequence generators for different
tables, here is a pair of them:

CREATE TABLE TBL_GEN_ABC_ID (
  ID bigint IDENTITY(1, 1) NOT NULL,
  DUMMY bit,
  CONSTRAINT PK_TBL_GEN_ABC_ID PRIMARY KEY CLUSTERED (ID)
)
GO
CREATE TABLE TBL_ABC (
  ABC_ID INT NOT NULL,
  ABC_NAME] VARCHAR(100) NOT NULL,
  CONSTRAINT PK_TBL_ABC PRIMARY KEY CLUSTERED (ABC_ID)
)
GO

Procedure is like this:
CREATE PROCEDURE spmy_get_next_id(
  @GEN_ID_NAME VARCHAR(100)='#NO TABLE',
  @ID bigint OUTPUT
)
AS
BEGIN

  SET @ID=NULL;
  
  DECLARE @GEN_ID bigint;
  SET @GEN_ID=0;
  
  IF (UPPER(@GEN_ID_NAME)='ABC_ID')
  BEGIN
 WHILE (1=1)
 BEGIN
 
   --generate id
   INSERT INTO TBL_GEN_ABC_ID (DUMMY)
   VALUES(0);
   SET @GEN_ID=@@IDENTITY; --get generated id

   IF(NOT EXISTS( --make sure it was not used
 SELECT ABC_ID
 FROM TBL_ABC
 WHERE [EMAIL PROTECTED])
 )
   BREAK;
 END

  END
  
  SET @[EMAIL PROTECTED]; 
  SELECT @ID AS ID;--for PHP to read resultset and value
  RETURN @ID;  --return value, not crucial
END
GO

so in PHP you can use modifed version of my function:

function db_get_next_id($mygenid=''){
  $i=0;
  $sql="
  DECLARE @MY_ID bigint, @r bigint
  EXECUTE @r=SPMY_GET_NEXT_ID \"$mygenid\", @MY_ID OUTPUT
  "
  ;
  
  if($qry=db_query($sql)){
 while($row=db_fetch_row($qry)){
 $i=$row[0]; break;
 }
 db_free_result($qry);
  }
  return $i;
}//end fun get next id

$new_id=db_get_next_id('ABC_ID');
(As I mentioned earlier, e.g. db_fetch_row is just using
mssql_fetch_row.. all of my db_xyz functions are like this.)

This works fine but subsequent mssql_query functions fail.
This may not be the ideal way of doing it, but it should not  cause any
harm. Everything else is working fine. Maybe I should just change the
way I use my procedures..
Thank you.


Previous Comments:


[2005-12-29 22:37:33] [EMAIL PROTECTED]

Frank, can you make any sense to this? :)

----------------

[2005-12-29 22:35:42] muratyaman at gmail dot com

Thank you.
I could not integrate php_dblib.dll :(
I tried to compile FreeTDS using Dev-C++ but could not get it working
with PHP.. I am stuck.

I was investigating the problem.
I have a function as follows:

function db_get_next_id($mygenid=''){
  $i=0;
  $sql="
  DECLARE @MY_ID INT8, @r int8
  EXECUTE @r= SPMY_GET_NEXT_ID \"$mygenid\", @MY_ID OUTPUT
  "
  ;
  
  if($qry=db_query($sql)){
 while($row=db_fetch_row($qry)){
 $i=$row[0]; break;
 }
 db_free_result($qry);
  }
  return $i;
}//end fun get next id

$new_id=db_get_next_id('keyfield');

This just works fine, I found that after this, calls to the db fails
and produces the error. Because when I comment out the line calling
this function, I don't get any error message.
Any ideas?
Regards



[2005-12-29 22:15:50] [EMAIL PROTECTED]

Does using php_dblib.dll work any better or not?

----

[2005-12-29 17:36:44] muratyaman at gmail dot com

Hi!
I installed latest version of PHP (5.1.2rc2) but same :(
I found out that even the simplest of my pages have same problem
regardless of combobox.
My db abstraction layer is really simple:
I just replaced "mssql_abc" functions with "db_abc" functions.
I will try the DLL you recommended.
I think I need to find out when/how/why the connection is broken if
that's the case.. Unfortunately, there are not many traces, I looked at
Apache log, SQL server log.. nothing. I do not have anything apart from
PHP errors, because mssql_get_last_message() does not contain
anything.

Regards..



[2005-12-29 16:53:51] [EMAIL PROTECTED]

Can you reproduce the error with out the DB abstraction layer you are
using?
The data send to the server contains garbage, and this could be an
indication that you are getting this error in a multithreaded
environment. The standard MSSQL extension is not thread safe du to the
msdblib library used to build the extension.
You could replace php_mssql.dll with php_dblib.dll. It provides the
same functions but

#35839 [Fbk->Opn]: mssql_query(): "Possible network error: Bad token from SQL Server.."

2005-12-29 Thread muratyaman at gmail dot com
 ID:   35839
 User updated by:  muratyaman at gmail dot com
 Reported By:  muratyaman at gmail dot com
-Status:   Feedback
+Status:   Open
 Bug Type: MSSQL related
 Operating System: Win XP Pro SP2
 PHP Version:  5CVS-2005-12-29 (snap)
 New Comment:

Thank you.
I could not integrate php_dblib.dll :(
I tried to compile FreeTDS using Dev-C++ but could not get it working
with PHP.. I am stuck.

I was investigating the problem.
I have a function as follows:

function db_get_next_id($mygenid=''){
  $i=0;
  $sql="
  DECLARE @MY_ID INT8, @r int8
  EXECUTE @r= SPMY_GET_NEXT_ID \"$mygenid\", @MY_ID OUTPUT
  "
  ;
  
  if($qry=db_query($sql)){
 while($row=db_fetch_row($qry)){
 $i=$row[0]; break;
 }
 db_free_result($qry);
  }
  return $i;
}//end fun get next id

$new_id=db_get_next_id('keyfield');

This just works fine, I found that after this, calls to the db fails
and produces the error. Because when I comment out the line calling
this function, I don't get any error message.
Any ideas?
Regards


Previous Comments:


[2005-12-29 22:15:50] [EMAIL PROTECTED]

Does using php_dblib.dll work any better or not?

------------

[2005-12-29 17:36:44] muratyaman at gmail dot com

Hi!
I installed latest version of PHP (5.1.2rc2) but same :(
I found out that even the simplest of my pages have same problem
regardless of combobox.
My db abstraction layer is really simple:
I just replaced "mssql_abc" functions with "db_abc" functions.
I will try the DLL you recommended.
I think I need to find out when/how/why the connection is broken if
that's the case.. Unfortunately, there are not many traces, I looked at
Apache log, SQL server log.. nothing. I do not have anything apart from
PHP errors, because mssql_get_last_message() does not contain
anything.

Regards..



[2005-12-29 16:53:51] [EMAIL PROTECTED]

Can you reproduce the error with out the DB abstraction layer you are
using?
The data send to the server contains garbage, and this could be an
indication that you are getting this error in a multithreaded
environment. The standard MSSQL extension is not thread safe du to the
msdblib library used to build the extension.
You could replace php_mssql.dll with php_dblib.dll. It provides the
same functions but uses FreeTDS to create conenctions.

--------------------

[2005-12-29 16:33:49] muratyaman at gmail dot com

Description:

Error message is:
"mssql_query() [function.mssql-query]: Possible network error: Bad
token from SQL Server: Datastream processing out of sync. (severity 9)
   in file ... line ..."

I have a WinXP, Apache2, PHP5, MSDE2000 app and many pages inserting,
updating, deleting records..
Pages for inserts include code to return on error and not lose entered
data.


Reproduce code:
---
(Every page opens connection, queries database multiple times, closes
the connection.)

Create a form with a few textboxes and a combobox.
I create a combobox with:


db_combo simply uses mssql_query to select records from a table, fill
with options, create HTML code of a combobox with

  


I use a global $dbh to handle database connection, also use 
mssql_connect, mssql_select_db functions.

Expected result:

1. load page: tbl2_new.php 
   combobox FULL with records read from the table
2. post to  : tbl2_insert.php
   may not insert record because of normal reasons
3. return to: tbl2_new.php
   any entered data is post back
   combobox FULL with records read from the table
4. post to  : tbl2_insert.php
   insert record


Actual result:
--
1. load page: tbl2_new.php 
   with EMPTY combobox and ERROR
   connection is lost
   every call afterwards to mssql_query fails
2. post to  : tbl2_insert.php
   may or may not insert record
3. return to: tbl2_new.php
   any entered data is post back
   combobox FULL with records read from the table
   no problem at all

Briefly, "new" and "edit" pages are very much similar with comboboxes
etc. But on "new" pages, combobox cannot get any records on 1st run.

I could not figure out the problem.
But I think there is a communication problem when SQL server tries to
send the records from a table.

Thanks in advance.





-- 
Edit this bug report at http://bugs.php.net/?id=35839&edit=1


#35839 [Fbk->Opn]: mssql_query(): "Possible network error: Bad token from SQL Server.."

2005-12-29 Thread muratyaman at gmail dot com
 ID:   35839
 User updated by:  muratyaman at gmail dot com
 Reported By:  muratyaman at gmail dot com
-Status:   Feedback
+Status:   Open
 Bug Type: MSSQL related
 Operating System: Win XP Pro SP2
 PHP Version:  5.1.1
 New Comment:

Hi!
I installed latest version of PHP (5.1.2rc2) but same :(
I found out that even the simplest of my pages have same problem
regardless of combobox.
My db abstraction layer is really simple:
I just replaced "mssql_abc" functions with "db_abc" functions.
I will try the DLL you recommended.
I think I need to find out when/how/why the connection is broken if
that's the case.. Unfortunately, there are not many traces, I looked at
Apache log, SQL server log.. nothing. I do not have anything apart from
PHP errors, because mssql_get_last_message() does not contain
anything.

Regards..


Previous Comments:


[2005-12-29 16:53:51] [EMAIL PROTECTED]

Can you reproduce the error with out the DB abstraction layer you are
using?
The data send to the server contains garbage, and this could be an
indication that you are getting this error in a multithreaded
environment. The standard MSSQL extension is not thread safe du to the
msdblib library used to build the extension.
You could replace php_mssql.dll with php_dblib.dll. It provides the
same functions but uses FreeTDS to create conenctions.



[2005-12-29 16:37:20] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php5.1-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.1-win32-latest.zip



----

[2005-12-29 16:33:49] muratyaman at gmail dot com

Description:

Error message is:
"mssql_query() [function.mssql-query]: Possible network error: Bad
token from SQL Server: Datastream processing out of sync. (severity 9)
   in file ... line ..."

I have a WinXP, Apache2, PHP5, MSDE2000 app and many pages inserting,
updating, deleting records..
Pages for inserts include code to return on error and not lose entered
data.


Reproduce code:
---
(Every page opens connection, queries database multiple times, closes
the connection.)

Create a form with a few textboxes and a combobox.
I create a combobox with:


db_combo simply uses mssql_query to select records from a table, fill
with options, create HTML code of a combobox with

  


I use a global $dbh to handle database connection, also use 
mssql_connect, mssql_select_db functions.

Expected result:

1. load page: tbl2_new.php 
   combobox FULL with records read from the table
2. post to  : tbl2_insert.php
   may not insert record because of normal reasons
3. return to: tbl2_new.php
   any entered data is post back
   combobox FULL with records read from the table
4. post to  : tbl2_insert.php
   insert record


Actual result:
--
1. load page: tbl2_new.php 
   with EMPTY combobox and ERROR
   connection is lost
   every call afterwards to mssql_query fails
2. post to  : tbl2_insert.php
   may or may not insert record
3. return to: tbl2_new.php
   any entered data is post back
   combobox FULL with records read from the table
   no problem at all

Briefly, "new" and "edit" pages are very much similar with comboboxes
etc. But on "new" pages, combobox cannot get any records on 1st run.

I could not figure out the problem.
But I think there is a communication problem when SQL server tries to
send the records from a table.

Thanks in advance.





-- 
Edit this bug report at http://bugs.php.net/?id=35839&edit=1


#35839 [NEW]: mssql_query Possible network error Bad token from SQL Server..

2005-12-29 Thread muratyaman at gmail dot com
From: muratyaman at gmail dot com
Operating system: Win XP Pro SP2
PHP version:  5.1.1
PHP Bug Type: MSSQL related
Bug description:  mssql_query Possible network error Bad token from SQL Server..

Description:

Error message is:
"mssql_query() [function.mssql-query]: Possible network error: Bad token
from SQL Server: Datastream processing out of sync. (severity 9)
   in file ... line ..."

I have a WinXP, Apache2, PHP5, MSDE2000 app and many pages inserting,
updating, deleting records..
Pages for inserts include code to return on error and not lose entered
data.


Reproduce code:
---
(Every page opens connection, queries database multiple times, closes the
connection.)

Create a form with a few textboxes and a combobox.
I create a combobox with:


db_combo simply uses mssql_query to select records from a table, fill with
options, create HTML code of a combobox with

  


I use a global $dbh to handle database connection, also use 
mssql_connect, mssql_select_db functions.

Expected result:

1. load page: tbl2_new.php 
   combobox FULL with records read from the table
2. post to  : tbl2_insert.php
   may not insert record because of normal reasons
3. return to: tbl2_new.php
   any entered data is post back
   combobox FULL with records read from the table
4. post to  : tbl2_insert.php
   insert record


Actual result:
--
1. load page: tbl2_new.php 
   with EMPTY combobox and ERROR
   connection is lost
   every call afterwards to mssql_query fails
2. post to  : tbl2_insert.php
   may or may not insert record
3. return to: tbl2_new.php
   any entered data is post back
   combobox FULL with records read from the table
   no problem at all

Briefly, "new" and "edit" pages are very much similar with comboboxes etc.
But on "new" pages, combobox cannot get any records on 1st run.

I could not figure out the problem.
But I think there is a communication problem when SQL server tries to send
the records from a table.

Thanks in advance.

-- 
Edit bug report at http://bugs.php.net/?id=35839&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=35839&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): 
http://bugs.php.net/fix.php?id=35839&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=35839&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=35839&r=fixedcvs
Fixed in release: 
http://bugs.php.net/fix.php?id=35839&r=alreadyfixed
Need backtrace:   http://bugs.php.net/fix.php?id=35839&r=needtrace
Need Reproduce Script:http://bugs.php.net/fix.php?id=35839&r=needscript
Try newer version:http://bugs.php.net/fix.php?id=35839&r=oldversion
Not developer issue:  http://bugs.php.net/fix.php?id=35839&r=support
Expected behavior:http://bugs.php.net/fix.php?id=35839&r=notwrong
Not enough info:  
http://bugs.php.net/fix.php?id=35839&r=notenoughinfo
Submitted twice:  
http://bugs.php.net/fix.php?id=35839&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=35839&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=35839&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=35839&r=dst
IIS Stability:http://bugs.php.net/fix.php?id=35839&r=isapi
Install GNU Sed:  http://bugs.php.net/fix.php?id=35839&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=35839&r=float
No Zend Extensions:   http://bugs.php.net/fix.php?id=35839&r=nozend
MySQL Configuration Error:http://bugs.php.net/fix.php?id=35839&r=mysqlcfg