/** * Adds keys to an alter table query * * @param AlterTable $alter The alert table query * @param array $keys The table keys to add */ private function addKeys($alter, $keys) { // Get the fields out of the alter query $fields = $alter->Fields(); // Add keys if any of the fields have associated keys for ($i = 0; $i < count($fields); $i++) { // Grab the name of the field $name = $fields[$i]->Name(); // Make the column primary if the key is a primary key AND the associated name matches if (array_key_exists("primary", $keys) && $keys["primary"] == $name) { $alter->AddKey("primary", $keys["primary"]); } // If there are any unique keys if (array_key_exists("unique", $keys)) { // Add the unique keys as needed for ($j = 0; $j < count($keys["unique"]); $j++) { // If the name of the unique key matches, add the key if ($keys["unique"][$j] == $name) { $alter->AddKey("unique", $keys["unique"][$j]); } } } // If the column needs to be set to auto-increment if (array_key_exists("ai", $keys) && $keys["ai"] == $name) { $alter->SetAutoIncrement($keys["ai"]); } } }