PEAR Packages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPEAR Packages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old October 15th, 2003, 11:22 AM
koy koy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: uk
Posts: 4 koy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
PEAR- numRows() problem!

Dear all,
I am quite new to programming in general, and have started using php to create a web application. I am using the PEAR database abstraction layer but have hit a brick wall. The method numRows() is supposed to return a number but keep getting 'Object' instead. Below is part of my code:
php Code:
Original - php Code
  1.  
  2. $username = $_POST['username'];
  3.  
  4.  $username = stripslashes($username);
  5.  
  6.  
  7.  if(!$username){
  8.    echo "Please enter your password <br/>";
  9.    include 'login_form.html';
  10.    exit();
  11.  }
  12.  
  13.  $login_query = $db->query("SELECT * FROM users WHERE username = '$username'");
  14.  if (DB::iserror ($login_query)) {
  15.     die ($login_query->getMessage());
  16.  }
  17.  
  18.  $login_check = $login_query->numRows();
  19.  
  20.  echo "$login_check<br>";
  21.  
  22.  if($login_check > 0){
  23.     echo "Welcome!";
  24.  }
  25.  else{
  26.     echo "Cannot log you in";
  27.  }


The script returns the following:
Object
Welcome!

,every time, even when the username does not exist in the database. I have been tearing out my hair for the past week. I would appreciate any help anybody could give.
Yours,
Koy

Reply With Quote
  #2  
Old October 15th, 2003, 11:32 AM
CodeKadiya CodeKadiya is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Colombo,Sri Lanka
Posts: 2,313 CodeKadiya User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
Send a message via Yahoo to CodeKadiya
RE: PEAR- numRows() problem!

Can I see the numRows() function?

Reply With Quote
  #3  
Old October 15th, 2003, 11:42 AM
koy koy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: uk
Posts: 4 koy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: PEAR- numRows() problem!

numRows() is a PEAR DB method. I didn't create this method. Like your gundam icon by the way!

Reply With Quote
  #4  
Old October 15th, 2003, 08:00 PM
decka decka is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: NJ
Posts: 19 decka User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to decka
RE: PEAR- numRows() problem!

isnt it like: mysql_numrows(); ?



php Code:
Original - php Code
  1.  
  2. $query = "SELECT * FROM table";
  3. $result = mysql_query($query);
  4. $num = mysql_numrows($result);
  5. echo $num;

Reply With Quote
  #5  
Old October 15th, 2003, 08:01 PM
decka decka is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: NJ
Posts: 19 decka User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to decka
RE: PEAR- numRows() problem!

isnt it like: mysql_numrows(); ?



php Code:
Original - php Code
  1.  
  2. $query = "SELECT * FROM table";
  3. $result = mysql_query($query);
  4. $num = mysql_numrows($result);
  5. echo $num;

Reply With Quote
  #6  
Old October 16th, 2003, 09:34 AM
koy koy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: uk
Posts: 4 koy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: PEAR- numRows() problem!

Yes, it is like mysql_num_rows but I am using the PEAR DB abstraction layer. Has anyone else using PEAR had this problem or know how to solve it?

Reply With Quote
  #7  
Old January 8th, 2004, 02:44 AM
Vinny Vinny is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Heber Springs, Arkansas US
Posts: 1 Vinny User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to Vinny
RE: PEAR- numRows() problem!

echo $login_query->numRows();

Try not to assign the numRows() function to a variable

Good Luck

Reply With Quote
  #8  
Old January 18th, 2004, 12:40 PM
rd42 rd42 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: peoria, IL, USA
Posts: 64 rd42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Same Issue

Koy, did you ever find a solutions to this, I'm running into the same issue.

Reply With Quote
  #9  
Old January 19th, 2004, 08:47 PM
rd42 rd42 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: peoria, IL, USA
Posts: 64 rd42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: PEAR- numRows() problem!

I use PEAR and had the same problem counting rows and here is what I found to work for counting rows.

php Code:
Original - php Code
  1.  
  2. $sql77 = "SELECT COUNT(*) FROM tablename";
  3. $sqlResult = $db->query($sql77);
  4. while ($sqlRow = $sqlResult->fetchRow()) {
  5. echo $sqlRow[0];
  6. }



Reply With Quote
  #10  
Old June 15th, 2004, 11:01 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: PEAR- numRows() problem!

Hello,

try this :

php Code:
Original - php Code
  1. $res =& $db->query($req);
  2. $db->setOption('portability', DB_PORTABILITY_NUMROWS);
  3. echo $res->numRows()



Reply With Quote
  #11  
Old October 1st, 2004, 12:46 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: PEAR- numRows() problem!

suggest you look at your sql because that should work fine ive just tried it myself and it does. you some times get funny errors with pear if your sql isnt correct

Reply With Quote
  #12  
Old October 2nd, 2004, 12:48 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: PEAR- numRows() problem!

in php, especially when you are new to a set of functions... print_r($var) can be your friend... this takes whatever $var is and prints it out the the screen for you to visually inspect.. if you are not getting what you thought try print_r-ing it and you should be able to get a handle on just what that thing is.. print_r shows in ascii not html so wrap with <pre> tags to get the correct line breaks seen

print "<pre>";
print_r($thing);
print "</pre>";

Reply With Quote
  #13  
Old February 23rd, 2006, 08:15 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: PEAR- numRows() problem!

I ran into same issue. I found that I could get it to work if I changed my SQL statements to "select DISTINCT colname from table". Not sure what adding the DISTINCT did but it fixed my problem.

Reply With Quote
  #14  
Old June 14th, 2006, 07:13 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: PEAR- numRows() problem!

This code fixed my problem.

php:
--------------------------------------------------------------------------------
$res =& $db->query($req);
$db->setOption('portability', DB_PORTABILITY_NUMROWS);
echo $res->numRows();
?>

Reply With Quote