Page 1 of 1

wierd sql issue

Posted: Tue Oct 24, 2006 2:48 pm
by kingconnections
So I posted a question about this a while back and have been using this method ever since, but today I ran into a strange issue.

This involves mssql_query function and evaluating the results. Normally I do it as such:

Code: Select all

if ($result === false) 
{ 
  // error 
} 
elseif ($result === true) 
{ 
  // no rows 
} 
else 
{ 
  // you have rows 
}
According to the php.net manual this should and has been working:
Returns: A MS SQL result resource on success, TRUE if no rows were returned, or FALSE on error.

Today I came across a result that was not in the database so it returned 0 rows. But it did have a resource id so was evlauated as data.

Here is a print out of the number of rows and the queries that were executed.

Code: Select all

query Resource id #5 = SELECT Name FROM Computer WHERE (Name = 'FSILBIT201') AND (idComputer NOT IN (SELECT idComputer FROM computerMaintenance WHERE InMaintenanceNow = '1')) -- num rows =1
query Resource id #6 = SELECT Name FROM Computer WHERE (Name = 'FSILHFTR01') AND (idComputer NOT IN (SELECT idComputer FROM computerMaintenance WHERE InMaintenanceNow = '1')) -- num rows =1
query Resource id #7 = SELECT Name FROM Computer WHERE (Name = 'GOORCACCAPP1') AND (idComputer NOT IN (SELECT idComputer FROM computerMaintenance WHERE InMaintenanceNow = '1')) -- num rows =0
Any ideas? I expected for the num rows =0 to return a TRUE instead they returned a resource id?

Re: wierd sql issue

Posted: Tue Oct 24, 2006 2:53 pm
by volka
kingconnections wrote:According to the php.net manual this should and has been working:
Returns: A MS SQL result resource on success, TRUE if no rows were returned, or FALSE on error.
What version of the manual?
http://de2.php.net/manual/en/function.mysql-query.php wrote:Return Values

For SELECT, SHOW, DESCRIBE or EXPLAIN statements, mysql_query() returns a resource on success, or FALSE on error.

For other type of SQL statements, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

Posted: Tue Oct 24, 2006 2:55 pm
by kingconnections
Hmm not sure says for php 3,4,5

link is here:

http://us3.php.net/manual/en/function.mssql-query.php

And this is concerning MS SQL

Posted: Tue Oct 24, 2006 3:08 pm
by bob_the _builder
Hi,

Shouldnt it just be:

Code: Select all

if ($result == false) 
{
== not ===

Posted: Tue Oct 24, 2006 3:13 pm
by volka
:oops: me blind . mssql != mysql

Posted: Tue Oct 24, 2006 3:44 pm
by kingconnections
Actually I tried === and == and both had the same effect. I thought so too after I tested it.