|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-09-18 07:39 UTC] snick at getart dot ru
Description:
------------
When I try to execute T-SQL query with advanced instructions PHP was crash.
Tested with:
Apache v. 2.0.43
IIS v. 6.0
MSSQL v. 7.0
ntwdblib.dll v. 2000.80.194.0
Query must include:
- BEGIN TRAN and COMMIT / ROLLBACK TRAN;
- RAISEERROR() function call;
- Error in query before RAISERROR (eg. failed INSERT with 'Can not insert NULL into bla-bla-bla' message (msg 515))
Reproduce code:
---------------
// you must create database called 'myDB' and table
// 'myTable' with columns myField1 INT NOT NULL, myField2 VARCHAR(50) NOT NULL
/*
...db connection and selection
*/
$query = "BEGIN TRAN
DECLARE @Flag BIT
SET @Flag = 0
INSERT INTO myTable (myField2) VALUES ('akgfsjhdgf')
IF @Flag = 0
BEGIN
RAISERROR('Some error', 18, 10)
ROLLBACK TRAN
END
ELSE
COMMIT TRAN";
$result = mssql_query($query);
echo "Result is ".($result ? "true" : "false")."<br/>";
echo "DB Error is ".mssql_get_last_message()."<br/>";
Expected result:
----------------
PHP must return usual errors (if exists) and specified output:
Result is true
DB Error is Changed database context to 'myDB'
Actual result:
--------------
If PHP running as Apache module:
message box
"Apache.exe - Application Error
The instruction at '0x77f486f7' referenced memory at
'0x00000000'. The memory could not be 'read'"
If PHP running as standalone:
message box
"php.exe - Application Error
The instruction at '0x77f486f7' referenced memory at
'0x00000000'. The memory could not be 'read'"
If PHP running as ISAPI module:
IIS return in browser string "PHP has encountered an Access Violation at 77F47931"
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 19:00:01 2025 UTC |
I believe the problem here is in how mssql_query handles result sets that have multiple results returned, but none with rows (such as in this bug where there are multiple commands executed and multiple errors returned). In the php_mssql.c for PHP 4.3.4 the block at line 1145 reads: while ((num_fields = dbnumcols(mssql_ptr->link)) <= 0 && retvalue == SUCCEED) { retvalue = dbresults(mssql_ptr->link); } According to Microsoft (http://msdn.microsoft.com/library/en-us/dblibc/dbc_pdc04e_52sz.asp), however: "You must call dbresults until it returns NO_MORE_RESULTS, or any continued use of the DBPROCESS causes the DB-Library error 10038 'Results Pending'." As this code in php_mssql.c currently stands it stops looping the empty result sets too early becuase it's looking for SUCCEED instead of NO_MORE_RESULTS. Changing this code to: while ((num_fields = dbnumcols(mssql_ptr->link)) <= 0 && retvalue != NO_MORE_RESULTS) { retvalue = dbresults(mssql_ptr->link); } causes both SQL Server error messages generated by the sample query in the bug report to be correctly displayed and eliminates the fault.