473,657 Members | 2,576 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($St rQuery);

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_ass oc($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 4935
On 8 Oct, 04:52, BethH <hartman.b...@g mail.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_ass oc($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...@g mail.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($St rQuery);

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_ass oc($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
3369
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
3575
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 hosted by a C# application, see below. However I've completely failed to force the browser to continue processing script which *should* be controlled by returning a true VT_BOOL via pvaOut. I've tried returning bool, System.Boolean even...
4
2819
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 bc; string s; bc = Request.Browser; ....
3
2142
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 reading out the data with a simple SELECT statement I noticed it would only get 256 characters in the MSSQL_FETCH_ARRAY result. Don't know how I missed this before. Obviously a significant number! I checked the INI file for any settings. The...
11
2645
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 remaining fields are checkboxes, which allows the user to select true/false for each record in the text field. I.E. Field Txt Chkbx1 chkbx2 chkbox3 Eat Apples True False True Now, how to I loop through this table, for each...
13
2247
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
2078
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 reason. Is that possible the connection is closed? Dim strConn As String = "Server=localhost;Database=northwind;" + _ "Integrated Security=SSPI" Dim cnnNwind As SqlConnection = New SqlConnection(strConn) Try Dim strSql As String = "select * from...
2
2394
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 overcome several problems and can now connect to server and to database, but the mssql_query isnt returning anything. Code I use:
3
6643
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 recordsetclone, EOF is returning true. I think this may have something to do with the sort order of the underlying query, but I'm not sure; at any rate, I don't want to change the sort order. I thought you had to check for BOF and EOF, or at least EOF before...
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7324
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4151
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1953
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1611
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.