Пример #1
0
 /**
  * Drop column
  */
 private function drop_column($keys)
 {
     $this->data = self::getJSON($this->file, true);
     if (!is_array($keys)) {
         $keys = self::trim_array(explode(',', $keys));
     }
     $new_data = array();
     if (self::check_array($keys, true)) {
         self::$error = array('code' => 104, 'message' => 'Somthing wrong width parameters: "' . implode(',', $keys) . '"');
         return false;
     }
     if (!$this->check_table_keys($keys)) {
         self::$error = array('code' => 202, 'message' => 'Try to drop an unexisting column from table "' . $this->table . '"');
         return false;
     }
     foreach ($keys as $key) {
         if ($number = array_search($key, $this->data['settings']['keys'])) {
             unset($this->data['settings']['keys'][$number]);
         }
         if ($this->data['settings']['auto_increment'] == $key) {
             $this->data['settings']['auto_increment'] = false;
         }
         if (isset($this->data['settings']['default_values'][$key])) {
             unset($this->data['settings']['default_values'][$key]);
         }
     }
     foreach ($this->data['rows'] as $row) {
         foreach ($keys as $key) {
             unset($row[$key]);
         }
         $new_data[] = $row;
     }
     $this->data['rows'] = $new_data;
     return self::setJSON($this->file, $this->data);
 }