Bug #18149: INSERT/SELECT doesn't return resource, prevents any further queries

From: Date: Wed, 03 Jul 2002 18:41:24 +0000
Subject: Bug #18149: INSERT/SELECT doesn't return resource, prevents any further queries
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-13023@lists.php.net to get a copy of this message
From: mhackett@ese.ogi.edu Operating system: Windows 2000 Server PHP version: 4.2.1 PHP Bug Type: MSSQL related Bug description: INSERT/SELECT doesn't return resource, prevents any further queries When I do an INSERT statement that has a SELECT @@IDENTITY at the end, the result is not a resource, but just 1. I suppose that would make sense for an INSERT-only query, but this should be returning a resource for the result. (Transact SQL, the SQL flavor Microsoft SQL Server is powered by, has a special variable @@IDENTITY which returns the last primary key insert). This alone seems to me to be a bug, but the bigger problem comes next. As sson as I attempt to execute any more queries, either on the same page, or on any others, even if I start a new browser session, PHP chokes. mssql_connect() or _pconnect() returns no error, but any query or mssql_select_db() fails. This continues until I restart Apache. I've done a trace on the SQL server, and it shows that the last command (the INSERT ... SELECT @@IDENTITY) succeeds, but PHP subsequently stops sending commands. Even when PHP has apparently connected, the Enterprise Manger and trace show no new connections or USE statements. Here is a test snippet I used: mssql_pconnect(DB_DSN, DB_USER, DB_PASS); mssql_select_db('cmxreg'); $ret = mssql_query("INSERT INTO Users (UserName) VALUES ('sql_test') SELECT @@IDENTITY AS UserID"); echo $ret.'<br />'; echo mssql_result($ret, 0, 'UserID'); And the error message for the first run: Warning: mssql_result(): supplied argument is not a valid MS SQL-result resource in C:\SiteData\htdocs\regadmin\test.php on line 8 And subsequent runs: Warning: MS SQL: Unable to select database: cmxreg in C:\SiteData\htdocs\regadmin\test.php on line 5 Warning: MS SQL: Query failed in C:\SiteData\htdocs\regadmin\test.php on line 6 Warning: mssql_result(): supplied argument is not a valid MS SQL-result resource in C:\SiteData\htdocs\regadmin\test.php on line 8 -- Edit bug report at http://bugs.php.net/?id=18149&edit=1 -- Fixed in CVS: http://bugs.php.net/fix.php?id=18149&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=18149&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=18149&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=18149&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=18149&r=support Expected behavior: http://bugs.php.net/fix.php?id=18149&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=18149&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=18149&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=18149&r=globals

« previous php.bugs (#13023) next »