Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP和MySQL中查询结果判断的一个问题_Php_Mysql_Pdo - Fatal编程技术网

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:你说得对,起初我认为是这样,但后来没有: