Beispiel #1
0
 /**
  * @return void 
  */
 public function create_db_index($table, $column, $unique = false, $length = null)
 {
     if (!is_array($column)) {
         $column = [$column];
     }
     if (!is_null($length)) {
         if (!is_array($length)) {
             $length = [$length];
         }
     }
     $iname = text::encode_filename($table);
     foreach ($column as $i => $c) {
         if (!text::check_name($c)) {
             die("Illegal column {$c}");
         }
         $iname .= '_' . $c;
         $column[$i] = "`" . $column[$i] . "`";
         if (is_int($length[$i]) && $length[$i] > 0) {
             $column[$i] .= "(" . $length[$i] . ")";
         }
     }
     $iname = text::cut($iname, 50);
     if ($table = $this->table_full_name($table, 1)) {
         $this->db->raw_query("\n\t\t\tCREATE " . ($unique ? "UNIQUE " : "") . "INDEX `{$iname}`\n      ON {$table} ( " . implode(", ", $column) . " )");
     }
     return $this;
 }