daily pastebin goal
2%
SHARE
TWEET

Untitled

a guest Apr 26th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. class Extend_PDO extends PDO {
  3.  
  4.    private $fetch_mode = PDO::FETCH_ASSOC;
  5.  
  6.    function __construct($dsn, $user = NULL, $pass = NULL, $options = NULL) {
  7.       parent::__construct($dsn, $user, $pass, $options);
  8.    }
  9.  
  10.    function setFetchMode($fetch_mode) {
  11.       $this->fetch_mode = $fetch_mode;
  12.    }
  13.  
  14.    function tableStatus($table) {
  15.       $query = 'SHOW TABLE STATUS LIKE "'.$table.'"';
  16.       $stmt = parent::prepare($query);
  17.       $result = $stmt->execute();
  18.       $rtval = $stmt->fetch(PDO::FETCH_ASSOC);
  19.       $stmt->closeCursor();
  20.       return $rtval;
  21.    }
  22.  
  23.    function query($sql) {
  24.       // Not sure yet if we truly need to extend PDOStatement
  25.       # $stmt = parent::prepare($sql, array(PDO::ATTR_STATEMENT_CLASS=>array('Extend_PDOStatement')));
  26.       # $stmt->execute();
  27.       $stmt = parent::query($sql);
  28.       if($stmt) {
  29.          $stmt->setFetchMode($this->fetch_mode);
  30.       }
  31.       return $stmt;
  32.    }
  33.  
  34. }
  35.  
  36. class Extend_PDOStatement extends PDOStatement {}
  37.  
  38. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top