function.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. require_once '../path.php';
  3. class CollectInfo
  4. {
  5. private $dbh;
  6. private $buffer;
  7. public function __construct() {
  8. $dns = "sqlite:"._FILE_DB_USER_ARTICLE_;
  9. $this->dbh = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
  10. $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  11. $buffer = array();
  12. }
  13. public function get($id){
  14. if(empty($id)){
  15. return array("title"=>"","id"=>"");
  16. }
  17. if(isset($buffer[$id])){
  18. return $buffer[$id];
  19. }
  20. if($this->dbh){
  21. $query = "SELECT id,title FROM collect WHERE id= ? limit 0,10";
  22. $stmt = $this->dbh->prepare($query);
  23. $stmt->execute(array($id));
  24. $collect = $stmt->fetch(PDO::FETCH_ASSOC);
  25. if($collect){
  26. $buffer[$id] = $collect;
  27. return $buffer[$id];
  28. }
  29. else{
  30. $buffer[$id] =false;
  31. return $buffer[$id];
  32. }
  33. }
  34. else{
  35. $buffer[$id] = false;
  36. return $buffer[$id];
  37. }
  38. }
  39. }
  40. ?>