123456789101112131415161718192021222324252627282930 |
- <?php
- /**
- * Description of DBObjectAutoCreate
- *
- * Will automatically create any missing DB structures
- *
- * @author robert.marshall
- */
- class DBObjectAutoCreate extends DBObject {
- private static $_run=array();
-
- protected static function CreateTable($table){
- if (isset(self::$_run[$table]) && self::$_run[$table])
- return;
-
- $PDO=self::GetPDO();
- $prep=$PDO->prepare("SHOW TABLES LIKE ?");
- $prep->execute(array($table));
- if ($prep->rowCount()<1)
- DBScriptRunner::RunScript("create_$table.sql");
-
- self::$_run[$table]=true;
- }
- public function __construct($table, $key, $id) {
- self::CreateTable($table);
- parent::__construct($table, $key, $id);
- }
- }
|