/** * Removes an index. * * @param string $table The table * @param string $index The index * @param bool $debug Dump the query * @return bool TRUE if the index no longer exists * @since 4.6.0 * @example * if (safe_drop_index('myTable', 'primary')) * { * echo "Primary key no longer exists in 'myTable'."; * } */ function safe_drop_index($table, $index, $debug = false) { if (!safe_index($table, $index, $debug)) { return true; } if (strtolower($index) === 'primary') { $q = 'alter table ' . safe_pfx($table) . ' drop primary key'; } else { $q = 'drop index `' . $index . '` on ' . safe_pfx($table); } return (bool) safe_query($q, $debug); }
/** * Removes an index. * * @param string $table The table * @param string $index The index * @param bool $debug Dump the query * @return bool TRUE if the index no longer exists * @since 4.6.0 * @example * if (safe_drop_index('myTable', 'primary')) * { * echo "Primary key no longer exists in 'myTable'."; * } */ function safe_drop_index($table, $index, $debug = false) { if (!safe_index($table, $index, $debug)) { return true; } if (strtolower($index) === 'primary') { $q = "ALTER TABLE " . safe_pfx($table) . " DROP PRIMARY KEY"; } else { $q = "DROP INDEX `{$index}` ON " . safe_pfx($table); } return (bool) safe_query($q, $debug); }