ODBC equivalent to mysql_num_rows()

Does anybody out there Know the equivalent odbc function to mysql_num_rows(). I tried to use odbc_num_rows but it returns -1 when i replace the mysql function below. Or is there an alternative solution?

if (odbc_num_rows($result) == -1) {
        // the user id and password match,  
        // set the session
        $_SESSION['db_is_logged_in'] = true;
        // after login move to the main page
        header('Location: main1.php');
        exit;
LVL 2
generaliAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Muhammad WasifCommented:
This function will return -1 on error. Your sql query is correct?

For details see http://www.php.net/odbc_num_rows
0
Muhammad WasifCommented:
also check the user comments on the page, specially the first one i.e.
odbc_num_rows for access does return -1. I use count($resultset);
0
generaliAuthor Commented:
Yeah id had a look at that link youve provided and gathered that it returned -1 for access. Im trying to set up a basic login system where my uid and pswd are stored in access, just converting the code from some ihave used from mysql. i tried the count($result) but this just lets me login with any password. the code is below:

<?php
// start the session
session_start();
$errorMessage = '';
if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) {
    $cnx = odbc_connect( 'MultiSport' , 'root', '' );
    if (!$cnx) {
        Error_handler( "Error in odbc_connect" , $cnx );
    }
     
    $userId   = $_POST['txtUserId'];
    $password = $_POST['txtPassword'];
     
    // check if the user id and password combination exist in database
    $sql = "SELECT user_id  
            FROM user_auth
            WHERE user_id = '$userId' AND password = '$password'";
     
    $result = odbc_exec( $cnx, $sql);
      if (!$result) {
        Error_handler( "Error in odbc_exec( no cursor returned ) " , $cnx );
    }
     
    if (odbc_num_rows($result) == 1) {
        // the user id and password match,  
        // set the session
        $_SESSION['db_is_logged_in'] = true;
        // after login we move to the main page
        header('Location: main1.php');
        exit;
    } else {
        $errorMessage = 'Sorry, wrong user id / password';
    }
      
     
    odbc_close( $cnx);
}
?>

have no end of problems with odbc, much prefer php/mysql.
0
Muhammad WasifCommented:
I have removed odbc_num_rows() and comparing the returned password from the DB.

Code is not tested, hope it will work. Change the code in this way

<?php
// start the session
session_start();
$errorMessage = '';
if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) {
    $cnx = odbc_connect( 'MultiSport' , 'root', '' );
    if (!$cnx) {
        Error_handler( "Error in odbc_connect" , $cnx );
    }
     
    $userId   = $_POST['txtUserId'];
    $password = $_POST['txtPassword'];
     
    // check if the user id and password combination exist in database
    $sql = "SELECT user_id  
            FROM user_auth
            WHERE user_id = '$userId' AND password = '$password'";
     
    $result = odbc_exec( $cnx, $sql);
     if (!$result) {
        Error_handler( "Error in odbc_exec( no cursor returned ) " , $cnx );
    }
   
      $rs = odbc_fetch_array($result);
    if ($userId==$rs["user_id"] && $password==$rs["password"]) {
        // the user id and password match,
        // set the session
        $_SESSION['db_is_logged_in'] = true;
        // after login we move to the main page
        header('Location: main1.php');
        exit;
    } else {
        $errorMessage = 'Sorry, wrong user id / password';
    }
     
    odbc_close( $cnx);
}
?>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
generaliAuthor Commented:
Works fine, thanks a lot. I just had to add the 'password' field to the select query which took me a while to figure out being the amatuer that i am!!

Thanks again
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.