A question about query result judgement in PHP and MySQL
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.Some开发者_StackOverflowone 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....
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
}
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论