tags:

views:

39

answers:

1

Code as follows:

$db = DatabaseService::getInstance();     //get a database handle,base on pdo
$sql = "select * from authusers where ssouid = '".$ssouid."' order by regtime";
$res = $db->query($sql);

if($res && $res->fetch())   // here is the Problem line
{
  //do something
}
else
{
  //raise some exception
}

In the problem line,I want the condition to find out whether some record(s) in database has been fetched or not.But I found somehow it didn't always work.Someone suggested me to use select count(*) as num ... to do this ,but I think that would be some kinda of duplicate query as select * from....

A: 

This should also work because query made its way to db:

if(mysql_num_rows($res))   // here is the Problem line
{
  //do something
}
else
{
  //raise some exception
}
Sarfraz
That's a solution for short code,thanks.
SpawnCxy
@SpawnCxy: that's good news any ways :)
Sarfraz
@Justin Johnson: you are right, initially i though that but then did not do :)
Sarfraz