DBObjectAutoCreate.php 707 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. /**
  3. * Description of DBObjectAutoCreate
  4. *
  5. * Will automatically create any missing DB structures
  6. *
  7. * @author robert.marshall
  8. */
  9. class DBObjectAutoCreate extends DBObject {
  10. private static $_run=array();
  11. protected static function CreateTable($table){
  12. if (isset(self::$_run[$table]) && self::$_run[$table])
  13. return;
  14. $PDO=self::GetPDO();
  15. $prep=$PDO->prepare("SHOW TABLES LIKE ?");
  16. $prep->execute(array($table));
  17. if ($prep->rowCount()<1)
  18. DBScriptRunner::RunScript("create_$table.sql");
  19. self::$_run[$table]=true;
  20. }
  21. public function __construct($table, $key, $id) {
  22. self::CreateTable($table);
  23. parent::__construct($table, $key, $id);
  24. }
  25. }