note 52341 added to function.mssql-query
| From: | vgr at europeanexperts dot org | Date: | Thu, 28 Apr 2005 11:53:07 +0000 |
| Subject: | note 52341 added to function.mssql-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-88683@lists.php.net to get a copy of this message | ||
The above is not (completely) true about the returned value.
I have the example of a perfectly working query (tested in isql and other SQL-Server interfaces)
returning no rows and no error messages at all, BUT mssql_query() returns FALSE with the "error
message" (obtained from mssql_get_last_message() ) being "Changed database context
to..."
That query is very simple and does usually return very few rows, if any.
Adding the "context" - full tablename qualifier, like "database501.dbo." - does
NOT solve the issue.
I had to code something like this
//VGR28042005 FIXed problem with SQL-Server sending "Changed database context" and
mssql_query returning FALSE !!!
$z=@mssql_query($Query_String,$this->Link_ID);
if ($z===FALSE) {
$theerror=mssql_get_last_message(); // last one returned
if (substr($theerror,0,24)=='Changed database context') $z=0;
}
//EoFix
$this->result=$z;
if ($z!==FALSE) {
// ok
$this->row=0;
$this->record_count=($z==0)?0:mssql_num_rows($this->result); //VGR28042005 FIX
return TRUE;
} else {
$this->Error=$theerror;
return FALSE;
} // EoAdd
in stead of the - classical -
if (($this->result=@mssql_query($Query_String,$this->Link_ID))!==FALSE) {
// ok
$this->row=0;
$this->record_count=mssql_num_rows($this->result);
return TRUE;
} else { // ko
$theerror=mssql_get_last_message(); // last one returned
return FALSE;
}
Playing with error message levels and error levels didn't help neither.
I precise that I'm using FreeTDS on *nix and haven't tested if this also happens on
Windows with the ntwdblib.dll in stead.
Hope This Helps someone someday ;-)
-----------------------------
www.europeanexperts.org
----
Manual Page -- http://www.php.net/manual/en/function.mssql-query.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52341
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52341&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52341&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52341&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52341&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52341&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52341&report=yes
Search -- http://master.php.net/manage/user-notes.php