473,503 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MSSQL_QUERY not returning True

According to php.net, mssql_query is supposed to return true when no
rows are returned. I'm actually getting an empty resource identifier
instead of true.

The table is empty, there are no rows in it at all, so mssql_query
should always return true, but it isn't. Am I missing something?
Here's my code:

$StrQuery = "SELECT * FROM BookMarks WHERE UserName='" . $ID . "'";
$Result = mssql_query($StrQuery);

I'm not sure how I could have messed it up. I tried looking for bool-
true (=== TRUE), but it didn't catch it. So then I tried any true (==
TRUE), and it worked. So then I tried looking for a bool (is_bool)
and it didn't catch it. Finally, I had it just print the result and
it gives me a resource identifier.

It keeps trucking through as if it had actually found something. But
when I do this:

while ($Row = mssql_fetch_assoc($Result)){
[code to make a table with the data]
};

nothing happens, because, of course, there are no actual rows, only
imaginary ones.

I've changed my code to check if the array is false before starting
the while loop, but that seems like a weird way to go just to see if
there's any data to work with.

Any Suggestions?

Oct 8 '07 #1
2 4924
On 8 Oct, 04:52, BethH <hartman.b...@gmail.comwrote:
According to php.net, mssql_query is supposed to return true when no
rows are returned. I'm actually getting an empty resource identifier
instead of true.
I've not checked the manual, but I'd be very surprised if that was the
case. Certainly it should return false if the query fails, and a valid
resource if successful. Note that in PHP in a boolean context, a non-
zero value is dynamically retyped to a true boolean and zero to false.
I'm not sure how I could have messed it up. I tried looking for bool-
true (=== TRUE), but it didn't catch it. So then I tried any true (==
TRUE), and it worked. So then I tried looking for a bool (is_bool)
and it didn't catch it. Finally, I had it just print the result and
it gives me a resource identifier.
Try:

if ( $Result ) {
// query worked, but we don't know how many rows it returned until
we go looking
$count=0;
while ($Row = mssql_fetch_assoc($Result)){
$count++;
[code to make a table with the data]

}
if (!$count) {
print "No rows returned";
}
} else {
// query has failed - but should already have thrown an error
}

Alternatively use the mssql_num_rows() function.

C.

Oct 8 '07 #2
On Oct 7, 11:52 pm, BethH <hartman.b...@gmail.comwrote:
According to php.net, mssql_query is supposed to return true when no
rows are returned. I'm actually getting an empty resource identifier
instead of true.

The table is empty, there are no rows in it at all, so mssql_query
should always return true, but it isn't. Am I missing something?
Here's my code:

$StrQuery = "SELECT * FROM BookMarks WHERE UserName='" . $ID . "'";
$Result = mssql_query($StrQuery);

I'm not sure how I could have messed it up. I tried looking for bool-
true (=== TRUE), but it didn't catch it. So then I tried any true (==
TRUE), and it worked. So then I tried looking for a bool (is_bool)
and it didn't catch it. Finally, I had it just print the result and
it gives me a resource identifier.

It keeps trucking through as if it had actually found something. But
when I do this:

while ($Row = mssql_fetch_assoc($Result)){
[code to make a table with the data]

};

nothing happens, because, of course, there are no actual rows, only
imaginary ones.

I've changed my code to check if the array is false before starting
the while loop, but that seems like a weird way to go just to see if
there's any data to work with.

Any Suggestions?
You're getting confused on the definition of "when no rows are
returned." They're talking about a query that doesn't actually return
rows, like insert, update, or delete. A query that returns a result
(like select) will always return a resource identifier, regardless of
how many rows are in the result.

Oct 8 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

35
3339
by: Steven Bethard | last post by:
I have lists containing values that are all either True, False or None, e.g.: etc. For a given list: * If all values are None, the function should return None.
0
3568
by: John Constant | last post by:
Using the MS C++ Example http://support.microsoft.com/default.aspx?scid=kb;en-us;261003 I've successfully managed to trap and log Script Errors that are generated by the WebBrowser (IE 6) which is...
4
2802
by: Earl T | last post by:
When I try to get the netscape version for version 7, I get the HttpBrowserCapabilities class returning the version as 5 and not 7. (see code and output below) CODE HttpBrowserCapabilities...
3
2136
by: Gazchurchend | last post by:
Hi Ive been using PHP to query data from SQL Server using MSSQL_QUERY for a while now, but recently noticed a problem. I have a notes field in the database (varchar 6000) for entering text. When...
11
2625
by: klove1209 | last post by:
Good afternoon, Can someone please guide me towards how to return records from a table. I currently have a table with about 21 fields, and 21 records. I have one field that is just text and the...
13
2232
by: agent-s | last post by:
I have a function, generally described as so: def function(args): if condition: if condition2: function(args+1) elif condition3: print "text" return True else:
10
2057
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I'm using this coding to get 2 resultsets thru datareader and then load them into 2 datatables and bind the datatables to datagridviews. But sdrGrid.NextResult() is returning false for some...
2
2388
by: Lado.Leskovec | last post by:
HI! I have been using MySQL in connection with PHP for fun for several years now, but at work they recently wanted me to develop an application, that uses MS SQL server 2005. I managed to...
3
6626
rsmccli
by: rsmccli | last post by:
Access 2002 Hi. I have a command button that will "approve" all records currently being looked at by an "approver". For some reason, even though there are multiple records that exist in the...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7460
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.