コード例 #1
0
ファイル: DbBuilder.php プロジェクト: pointdeb/dcom-db
 /**
  * execute the query
  *
  *@return boolean
  */
 public function execute()
 {
     if ($this->_exist) {
         $this->_sql .= ' IF NOT EXISTS ';
     }
     if (is_string($this->_dbName) && $this->_dbName != null) {
         $this->_sql .= $this->_dbName;
     } else {
         if (DB_NAME != null && $this->_auto != false) {
             $this->_dbName = DATABASE;
             $this->_sql .= $this->_dbName;
         } else {
             new DExceptions("dbName null for setName(dbName) or dbBuilder(dbName) or You haven't set DB_NAME before", 405);
             return false;
         }
     }
     $this->_sql .= ' DEFAULT CHARACTER SET ' . $this->_dataType;
     $this->_sql .= ' COLLATE ' . $this->_collate . ';';
     try {
         $this->_req = parent::connect();
         $req = $this->_req->query($this->_sql);
         return $req;
     } catch (\PDOException $e) {
         new DExceptions($e->getMessage(), $getCode());
     }
 }
コード例 #2
0
ファイル: TabBuilder.php プロジェクト: pointdeb/dcom-db
 public function execute()
 {
     //check the 1st option after CREATE TABLE and add if true,
     if ($this->_exist) {
         $this->_sql .= ' IF NOT EXISTS ';
     }
     //check the 3th option after CREATE TABLE and add table name if not null,
     if ($this->_tabName != null) {
         $this->_sql .= $this->_tabName . ' (';
     } else {
         new DExceptions("tabName null for setName(tabName)", 405);
     }
     //check the 4th option after CREATE TABLE and add column name  if not null,
     foreach ($this->_cols as $colName => $col) {
         // give colName INT(10);
         $this->_sql .= $colName . ' ' . $col['_colType'] . '(' . $col['_colLenght'] . ') ';
         //check not null option,
         if ($col['_null'] === 'nNull') {
             $this->_sql .= 'NOT NULL ';
         }
         //check the default values of column
         if ($col['_colDefault'] != null) {
             $this->_sql .= "DEFAULT '" . $col['_colDefault'] . "' ";
         }
         //check auto increment or not
         if ($col['_inc'] === 'ai') {
             //only Int can be auto increment
             if ($col['_colType'] === 'int' || $col['_colType'] === 'INT') {
                 $this->_sql .= " AUTO_INCREMENT ";
             } else {
                 $this->_error = 'Increment imposible for not INT';
                 new DExceptions("Increment not possible for not int at setConst(constType) ", 405);
             }
         }
         //limit for each column
         $this->_sql .= ', ';
     }
     //$this->_sql=preg_replace("#, $#","",$this->_sql);
     //check if constraint exist and add constraint to the sql command
     if (isset($this->_constraint['name'])) {
         $this->_sql .= 'CONSTRAINT ' . $this->_constraint['name'] . ' ';
     }
     //check if constraint type and column name are set,
     if (isset($this->_constraint['type']) && isset($this->_constraint['col'])) {
         switch ($this->_constraint['type']) {
             case 'pk':
                 //give PRIMARY KEY (colName)
                 $this->_sql .= 'PRIMARY KEY (' . $this->_constraint['col'] . ')';
                 break;
             case 'frng':
                 //give FOREING KEY (colName) REFERENCES rbef_ta(ref_col)
                 $this->_sql .= 'FOREING KEY (' . $this->_constraint['col'] . ') REFERENCES ' . $this->_constraint['ref_tab'] . ' (' . $this->_constraint['ref_col'] . ')';
                 break;
             case 'u':
                 //give UNIQUE (colName)
                 $this->_sql .= 'UNIQUE (' . $this->_constraint['col'] . ')';
                 break;
             default:
                 //default send error if none of those is checked, cause table always have constraint;
                 new DExceptions("set name of collumn as primary key for setConst({$col},{$constType})", 405);
                 break;
         }
     }
     //give ) ENGINE = engine name like InnoDB;
     $this->_sql .= ') ENGINE=' . $this->_engine . " AUTO_INCREMENT=0;";
     //conncet to server
     try {
         $this->_req = parent::connect();
         //select db to use
         $this->_req->query('USE ' . strtolower($this->_dbName));
         //ececute query
         $this->_req->query($this->_sql);
         $this->reset();
     } catch (\PDOException $e) {
         new DExceptions($e->getMessage(), $e->getCode());
     }
 }
コード例 #3
0
ファイル: Db.php プロジェクト: pointdeb/dcom-db
 public function delete()
 {
     $query = parent::prepare('DELETE FROM ' . $this->_data['tabName'] . ' ' . $this->_data['more'] . '');
     $query->execute($this->_data['donnee']);
 }