Guest User

Untitled

a guest
Oct 16th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. <?php
  2.  
  3. class MysqlMapper{
  4.  
  5. protected static $instance = null;
  6. protected $pdo;
  7.  
  8. const HOST = 'localhost';
  9. const DATABASE = '';
  10. const USER = '';
  11. const PASS = '';
  12.  
  13. public function __construct(){
  14. $this->pdo = new PDO(sprintf('mysql:host=%s;dbname=%s', HOST, DATABASE), USER, PASS);
  15. }
  16.  
  17. public static function getInstance(){
  18. if(self::$instance == null):
  19. self::$instance = new MysqlTableMapper();
  20. return self::$instance;
  21. else:
  22. return self::$instance;
  23. endif;
  24. }
  25.  
  26. public function mapColumns($table){
  27.  
  28. $stm = $this->pdo->prepare('SHOW COLUMNS FROM '.$table.' FROM '.DATABASE);
  29. $stm->setFetchMode(PDO::FETCH_ASSOC);
  30. $stm->execute();
  31.  
  32. return $stm->fetchAll();
  33.  
  34.  
  35. }
  36.  
  37. public function showTables(){
  38. $stm = $this->pdo->prepare('SHOW TABLES FROM '.DATABASE);
  39. $stm->setFetchMode(PDO::FETCH_ASSOC);
  40. $stm->execute();
  41. $tables = array();
  42. foreach($stm->fetchAll() as $table):
  43. $tables[] = $table['Tables_in_'.DATABASE];
  44. endforeach;
  45.  
  46. return $tables;
  47. }
  48.  
  49.  
  50. }
Add Comment
Please, Sign In to add comment