DbVersion.class.php (1501B)
1 <?php 2 3 4 namespace database; 5 6 7 abstract class DbVersion 8 { 9 const TYPE_MYSQL = 1; 10 const TYPE_POSTGRES = 2; 11 const TYPE_SQLITE = 3; 12 const TYPE_ORACLE = 4; // Attention: ORACLE is NOT really supported. 13 14 private $db; 15 private $tablePrefix; 16 private $tableSuffix; 17 18 /** 19 * Datenbank-RDBMS-Typ 20 */ 21 private $dbmsType; 22 23 /** 24 * DbVersion constructor. 25 * @param Database $db 26 */ 27 public function __construct(Database $db) 28 { 29 $this->db = $db; 30 31 switch ($db->conf['type']) { 32 case 'pdo': 33 if ( $db->conf['dsn'] ) { 34 $dsnParts = explode(':', $db->conf['dsn']); 35 $driver = $dsnParts[0]; 36 }else { 37 $driver = $db->conf['driver']; 38 } 39 switch ($driver) { 40 case 'mysql': 41 $this->dbmsType = DbVersion::TYPE_MYSQL; 42 break; 43 case 'pgsql': 44 $this->dbmsType = DbVersion::TYPE_POSTGRES; 45 break; 46 case 'sqlite': 47 $this->dbmsType = DbVersion::TYPE_SQLITE; 48 break; 49 default: 50 throw new \LogicException('Unknown PDO driver: ' . $driver); 51 } 52 break; 53 default: 54 // for now we are only supporting PDO. 55 throw new \LogicException('Unknown DBMS type: ' . $db->conf['type']); 56 } 57 58 $this->tablePrefix = $db->conf['prefix']; 59 $this->tableSuffix = $db->conf['suffix']; 60 } 61 62 // Muss überschrieben werden! 63 abstract function update(); 64 65 66 public function table( $tableName ) { 67 return new Table( $this->getDb(),$this->dbmsType, $tableName ); 68 } 69 70 71 /** 72 * @return Database 73 */ 74 function getDb() 75 { 76 return $this->db; 77 } 78 79 }