PHP和MySQL中查询结果判断的一个问题
代码如下:PHP和MySQL中查询结果判断的一个问题,php,mysql,pdo,Php,Mysql,Pdo,代码如下: $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 Pro
$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
}
在问题行中,我希望条件确定数据库中的某些记录是否已被提取。但我发现它并不总是有效。有人建议我使用select count*作为num。。。要做到这一点,但我认为这将是一种重复的查询,如select*from…这也应该起作用,因为查询会进入数据库:
if(mysql_num_rows($res)) // here is the Problem line
{
//do something
}
else
{
//raise some exception
}
我们不知道数据库类中到底有什么,所以我认为我们不能真正提供帮助…Databaseserver类基于PDO:@Justin Johnson:你说得对,起初我认为是这样,但后来没有: