Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004
    Location
    Scotland
    Posts
    2

    Unanswered: 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.

  2. #2
    Join Date
    Mar 2004
    Location
    Scotland
    Posts
    2

    Talking

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

    shame...

    just ignore...

  3. #3
    Join Date
    Jan 2004
    Posts
    16
    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.
    infydime

  4. #4
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    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"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •