1
0
mirror of https://github.com/Yubico/yubikey-val.git synced 2025-02-01 01:52:18 +01:00

Don't use PDO rowCount function to get number of rows returned

because that isn't portable.  Patch from arte42.ripe in issue #7
(yubikey-val-2.1-php-rowcount.patch).
This commit is contained in:
Simon Josefsson 2010-05-17 13:20:49 +00:00
parent cc2ade0b3b
commit 393ef0c44e
3 changed files with 20 additions and 6 deletions

4
NEWS
View File

@ -2,6 +2,10 @@
* Fix undefined warnings, issue #8.
* Don't use PDO rowCount function to get number of rows returned
because that isn't portable. Patch from arte42.ripe in issue #7
(yubikey-val-2.1-php-rowcount.patch).
* When number of sync servers equals zero, set sync result to success.
Patch from arte42.ripe in issue #7 (yubikey-val-2.1-syncres.patch).

View File

@ -96,7 +96,7 @@ class Db
try {
$this->dbh = new PDO($this->db_dsn, $this->db_username, $this->db_password, $this->db_options);
} catch (PDOException $e) {
$this->myLog->log(LOG_CRIT, "Database error: " . $e->getMessage());
$this->myLog->log(LOG_CRIT, "Database connection error: " . $e->getMessage());
$this->dbh=Null;
return false;
}
@ -109,7 +109,7 @@ class Db
$this->result = $this->dbh->query($query);
if (! $this->result){
$this->myLog->log(LOG_INFO, 'Database error: ' . print_r($this->dbh->errorInfo(), true));
$this->myLog->log(LOG_INFO, 'Database query error: ' . preg_replace('/\n/',' ',print_r($this->dbh->errorInfo(), true)));
return false;
}
if ($returnresult) return $this->result;
@ -305,6 +305,7 @@ or false on failure.
if ($nr==1) {
$row = $result->fetch(PDO::FETCH_ASSOC);
$result->closeCursor();
return $row;
}
else {
@ -312,6 +313,7 @@ or false on failure.
while($row = $result->fetch(PDO::FETCH_ASSOC)){
$collection[]=$row;
}
$result->closeCursor();
return $collection;
}
@ -366,8 +368,13 @@ or false on failure.
*/
public function rowCount()
{
if($this->result) return $this->result->rowCount();
else return 0;
if($this->result) {
$count=count($this->result->fetchAll());
$this->result->closeCursor();
return $count;
} else {
return 0;
}
}
/**
@ -405,4 +412,4 @@ or false on failure.
}
?>
?>

View File

@ -57,7 +57,9 @@ class SyncLib
function getClientData($client)
{
$res=$this->db->customQuery("SELECT id, secret FROM clients WHERE active AND id='" . $client . "'");
if($res->rowCount()>0) return $res->fetch(PDO::FETCH_ASSOC);
$r = $res->fetch(PDO::FETCH_ASSOC);
$res->closeCursor();
if ($r) return $r;
else return false;
}
@ -372,6 +374,7 @@ class SyncLib
}
} /* End of loop over each queue entry for a server */
$res->closeCursor();
} /* End of loop over each distinct server in queue */
return true;
}