1
0
mirror of https://github.com/Yubico/yubikey-val.git synced 2025-02-08 03:54:20 +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. * 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. * 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). Patch from arte42.ripe in issue #7 (yubikey-val-2.1-syncres.patch).

View File

@ -96,7 +96,7 @@ class Db
try { try {
$this->dbh = new PDO($this->db_dsn, $this->db_username, $this->db_password, $this->db_options); $this->dbh = new PDO($this->db_dsn, $this->db_username, $this->db_password, $this->db_options);
} catch (PDOException $e) { } 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; $this->dbh=Null;
return false; return false;
} }
@ -109,7 +109,7 @@ class Db
$this->result = $this->dbh->query($query); $this->result = $this->dbh->query($query);
if (! $this->result){ 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; return false;
} }
if ($returnresult) return $this->result; if ($returnresult) return $this->result;
@ -305,6 +305,7 @@ or false on failure.
if ($nr==1) { if ($nr==1) {
$row = $result->fetch(PDO::FETCH_ASSOC); $row = $result->fetch(PDO::FETCH_ASSOC);
$result->closeCursor();
return $row; return $row;
} }
else { else {
@ -312,6 +313,7 @@ or false on failure.
while($row = $result->fetch(PDO::FETCH_ASSOC)){ while($row = $result->fetch(PDO::FETCH_ASSOC)){
$collection[]=$row; $collection[]=$row;
} }
$result->closeCursor();
return $collection; return $collection;
} }
@ -366,8 +368,13 @@ or false on failure.
*/ */
public function rowCount() public function rowCount()
{ {
if($this->result) return $this->result->rowCount(); if($this->result) {
else return 0; $count=count($this->result->fetchAll());
$this->result->closeCursor();
return $count;
} else {
return 0;
}
} }
/** /**

View File

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