Wednesday, March 28, 2012

Is there a MSSQL Equivalent to mysql_num_rows()?

Hi there,
I am trying to find an equivalent to the MySQL function mysql_num_rows() that returns the number of rows returned in a result set.

I only found COUNT, but that doesnt work...

I am working on a web authentication system. The User enters UN and PW, which is then checked with the DB.

<?PHP
//connect to the mssql server
xxx
//select the database to use
xxx
// query
$query = "SELECT * from $table WHERE username='$username' AND pwd='$pwd'";
$result=@.mssql_query ($query);

$bla=COUNT($result);
echo $bla; // just to see if it works
if ($bla=1)
{
echo ("welcome $username");
}
elseif ($bla!=1)
{
echo ("auth required");
}

?>

$bla always returns 1... regardless of the UN and PW have been entered and whether they match an entry in the DB

Any thoughts?

cheers.Daft... mssql_num_rows()
the obvious is slapping my face.

shame...

just ignore...|||The 1 signifies that the query is executed, it is not the count of the resultset. If you are really looking at a good abstraction layer for database access in PHP, check
http://php.weblogs.com/ADODB
It is very easy to use.|||I'd do it like this:

$query = "if exists(SELECT * from $table WHERE username='$username' AND pwd='$pwd') select RetVal=1 else select RetVal=0"

No comments:

Post a Comment