| @@ 491-512 (lines=22) @@ | ||
| 488 | * |
|
| 489 | * @return bool |
|
| 490 | */ |
|
| 491 | public function addIndex($index = null, $fields = [], $index_type = 'INDEX') |
|
| 492 | { |
|
| 493 | if (empty($index) || empty($fields)) { |
|
| 494 | return false; |
|
| 495 | } |
|
| 496 | if ($this->showIndex($index)) { |
|
| 497 | return false; |
|
| 498 | } // index is exist |
|
| 499 | $index_type = strtoupper($index_type); |
|
| 500 | if (!in_array($index_type, ['INDEX', 'UNIQUE', 'SPATIAL', 'FULLTEXT'])) { |
|
| 501 | return false; |
|
| 502 | } |
|
| 503 | $fields = is_array($fields) ? implode(',', $fields) : $fields; |
|
| 504 | $sql = "ALTER TABLE {$this->table} ADD {$index_type} {$index} ( {$fields} )"; |
|
| 505 | if (!$result = $this->db->queryF($sql)) { |
|
| 506 | xoops_error($this->db->error() . '<br>' . $sql); |
|
| 507 | ||
| 508 | return false; |
|
| 509 | } |
|
| 510 | ||
| 511 | return true; |
|
| 512 | } |
|
| 513 | ||
| 514 | /** |
|
| 515 | * Drop index in a table |
|
| @@ 1336-1357 (lines=22) @@ | ||
| 1333 | * |
|
| 1334 | * @return bool |
|
| 1335 | */ |
|
| 1336 | public function addIndex($index = null, $fields = [], $index_type = 'INDEX') |
|
| 1337 | { |
|
| 1338 | if (empty($index) || empty($fields)) { |
|
| 1339 | return false; |
|
| 1340 | } |
|
| 1341 | if ($this->showIndex($index)) { |
|
| 1342 | return false; |
|
| 1343 | } // index is exist |
|
| 1344 | $index_type = strtoupper($index_type); |
|
| 1345 | if (!in_array($index_type, ['INDEX', 'UNIQUE', 'SPATIAL', 'FULLTEXT'])) { |
|
| 1346 | return false; |
|
| 1347 | } |
|
| 1348 | $fields = is_array($fields) ? implode(',', $fields) : $fields; |
|
| 1349 | $sql = "ALTER TABLE {$this->table} ADD {$index_type} {$index} ( {$fields} )"; |
|
| 1350 | if (!$result = $this->db->queryF($sql)) { |
|
| 1351 | xoops_error($this->db->error() . '<br>' . $sql); |
|
| 1352 | ||
| 1353 | return false; |
|
| 1354 | } |
|
| 1355 | ||
| 1356 | return true; |
|
| 1357 | } |
|
| 1358 | ||
| 1359 | /** |
|
| 1360 | * Drop index in a table |
|