diff --git a/NEWS b/NEWS index ac6f212..a4e32bc 100644 --- a/NEWS +++ b/NEWS @@ -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). diff --git a/ykval-db.php b/ykval-db.php index 9534926..74b5422 100644 --- a/ykval-db.php +++ b/ykval-db.php @@ -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. } -?> \ No newline at end of file +?> diff --git a/ykval-synclib.php b/ykval-synclib.php index 74635fa..ed89713 100644 --- a/ykval-synclib.php +++ b/ykval-synclib.php @@ -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; }