Exemplo n.º 1
0
 /**
  * Parent constructor sets up the DB connection, then we choose which Handler to use for generating the actual query.
  * The handler will set it's 'model' value to this model, so that it has access to the DB connection and so that
  * the functions here can handle the request
  */
 public function __construct()
 {
     parent::__construct();
     $config = Nutshell::getInstance()->config;
     $connectionName = $config->plugin->Mvc->connection;
     $handlerName = $config->plugin->Db->connections->{$connectionName}->handler;
     if (strtolower($handlerName) == 'mysql') {
         $this->handler = new MySQL($this);
     } elseif (strtolower($handlerName) == 'sqlite') {
         $this->handler = new SQLite($this);
     } else {
         throw new MvcQueryException(MvcQueryException::INVALID_HANDLER, $connectionName, $handlerName);
     }
 }
Exemplo n.º 2
0
 public function __construct()
 {
     parent::__construct();
     $this->configure();
     if (!empty($this->name) && count($this->primary) > 0 && !empty($this->columns)) {
         if (isset($this->db)) {
             // only creates the table when $autoCreate is true & This is a mySQL database
             if ($this->autoCreate && stristr(get_class($this->db), 'mysql')) {
                 $this->createTable();
             }
         } else {
             throw new Exception('DB connection not defined in config.');
         }
     } else {
         throw new Exception('CRUD Model is misconfigured. Name, Primary Key and Columns must be defined.');
     }
 }