num_rows

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • newladder
    New Member
    • Jan 2007
    • 15

    #1

    num_rows

    Hi,

    i have a code which is used to connect to database and get number of rows affteced from the SQL Query.
    when i run the query connecting to postgres DB it gives num_row as 0, but when i run the query connecting to mssql server DB it gives num_row as -1. Below is my code.

    $conn = odbc_connect('s erver','usernam e','password');
    $sql = "SELECT * FROM clients WHERE client_code='*' ";

    $result = odbc_exec($conn , $sql);
    $num_rows = odbc_num_rows($ result);
    echo "num of rows :".$num_rows ;

    Kindly suggest
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    You cannot get a number of rows from a connect statement.

    As far as your query is concerned, you probably have an error. It is good practice to test the result of queries after each execution. So you would get more information when you code it like this:
    [php]
    $conn = odbc_connect('s erver','usernam e','password')
    or die("Connect error: ".odbc_errormsg ());

    $sql = "SELECT * FROM clients WHERE client_code='*' ";
    $result = odbc_exec($conn , $sql)
    or die("SELECT error: ".odbc_errormsg ());

    $num_rows = odbc_num_rows($ result);
    echo "num of rows :".$num_rows ;
    [/php]
    Ronald :cool:

    Comment

    • newladder
      New Member
      • Jan 2007
      • 15

      #3
      Hi,
      i have tested the query but no results again. I get the same.

      Regards

      Comment

      • Bou
        New Member
        • Feb 2007
        • 1

        #4
        Originally posted by newladder
        Hi,
        i have tested the query but no results again. I get the same.

        Regards
        Try "\*" in the query instead of "*".

        Comment

        • newladder
          New Member
          • Jan 2007
          • 15

          #5
          Hi,

          I get differenet errors.
          [PHP]Warning: Unexpected character in input: '\' (ASCII=92) state=1 in c:\Inetpub\wwwr oot\dev\lib\log in_functions.ph p on line 399

          Warning: session_start() [function.sessio n-start]: Cannot send session cookie - headers already sent by (output started at c:\Inetpub\wwwr oot\dev\lib\log in_functions.ph p:399) in c:\Inetpub\wwwr oot\dev\lib\log in_functions.ph p on line 2

          Warning: session_start() [function.sessio n-start]: Cannot send session cache limiter - headers already sent (output started at c:\Inetpub\wwwr oot\dev\lib\log in_functions.ph p:399) in c:\Inetpub\wwwr oot\dev\lib\log in_functions.ph p on line 2

          client selection sql :0
          Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near '0'., SQL state 37000 in SQLExecDirect in c:\Inetpub\wwwr oot\dev\lib\log in_functions.ph p on line 401

          Warning: odbc_num_rows() : supplied argument is not a valid ODBC result resource in c:\Inetpub\wwwr oot\dev\lib\log in_functions.ph p on line 402[/PHP]

          Comment

          • newladder
            New Member
            • Jan 2007
            • 15

            #6
            Hi Friends,

            I got working, have one strange problem the if conditions are not working, it is not supporting at all. Any idea why ?

            Regards

            Comment

            • Motoma
              Recognized Expert Specialist
              • Jan 2007
              • 3236

              #7
              Originally posted by newladder
              Hi Friends,

              I got working, have one strange problem the if conditions are not working, it is not supporting at all. Any idea why ?

              Regards
              Not quite sure what you mean by that.
              Reword your question and I'll see if I can tell you what's going on.

              Comment

              • newladder
                New Member
                • Jan 2007
                • 15

                #8
                Hi,

                [PHP] $sql = "SELECT * FROM users WHERE LOWER(username) ='" . strtolower($use rname) . "' AND (client_code='* ' or client_code='$c lient_code')";
                $result = odbc_exec($conn , $sql);

                while($row = odbc_fetch_arra y($result))
                {
                $active = $row['active'];
                $pwd = $row['password'];
                }

                echo "data is :".$active;[/PHP]

                iam getting the value of the variable $active however if we use the same with below code.

                [PHP] if ($row = odbc_fetch_row( $result) > 0)
                {
                $active = $row['active'];
                $pwd = $row['password'];
                }
                echo "data is :".$active;[/PHP]


                This doesn't work

                Regards

                Comment

                • Motoma
                  Recognized Expert Specialist
                  • Jan 2007
                  • 3236

                  #9
                  Originally posted by newladder
                  Hi,

                  [PHP] $sql = "SELECT * FROM users WHERE LOWER(username) ='" . strtolower($use rname) . "' AND (client_code='* ' or client_code='$c lient_code')";
                  $result = odbc_exec($conn , $sql);

                  while($row = odbc_fetch_arra y($result))
                  {
                  $active = $row['active'];
                  $pwd = $row['password'];
                  }

                  echo "data is :".$active;[/PHP]

                  iam getting the value of the variable $active however if we use the same with below code.

                  [PHP] if ($row = odbc_fetch_row( $result) > 0)
                  {
                  $active = $row['active'];
                  $pwd = $row['password'];
                  }
                  echo "data is :".$active;[/PHP]


                  This doesn't work

                  Regards
                  That is because $row is an array, and I have no idea how it compares to 0.

                  What you probably want to do is this:
                  [PHP]
                  if (count($row = odbc_fetch_row( $result)) > 0)
                  {
                  $active = $row['active'];
                  $pwd = $row['password'];
                  }
                  echo "data is :".$active;
                  [/PHP]

                  Comment

                  Working...