Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class MysqlMapper{
- protected static $instance = null;
- protected $pdo;
- const HOST = 'localhost';
- const DATABASE = '';
- const USER = '';
- const PASS = '';
- public function __construct(){
- $this->pdo = new PDO(sprintf('mysql:host=%s;dbname=%s', HOST, DATABASE), USER, PASS);
- }
- public static function getInstance(){
- if(self::$instance == null):
- self::$instance = new MysqlTableMapper();
- return self::$instance;
- else:
- return self::$instance;
- endif;
- }
- public function mapColumns($table){
- $stm = $this->pdo->prepare('SHOW COLUMNS FROM '.$table.' FROM '.DATABASE);
- $stm->setFetchMode(PDO::FETCH_ASSOC);
- $stm->execute();
- return $stm->fetchAll();
- }
- public function showTables(){
- $stm = $this->pdo->prepare('SHOW TABLES FROM '.DATABASE);
- $stm->setFetchMode(PDO::FETCH_ASSOC);
- $stm->execute();
- $tables = array();
- foreach($stm->fetchAll() as $table):
- $tables[] = $table['Tables_in_'.DATABASE];
- endforeach;
- return $tables;
- }
- }
Add Comment
Please, Sign In to add comment