TableEditor.php
public function addFields(array $fields)
    {
        foreach ($fields as $field)
        {
            $name = $field->getName();
            $addFields[$name] = $field; # we key by name to prevent duplicates!
        }
        
        $keysString = "";
        $fieldStrings = array();
        
        foreach ($addFields as $fieldName => $field)
        {
            $fieldStrings[] = $field->getFieldString();
                
            /* @var $field DatabaseField */
            if ($field->isPrimaryKey())
            {
                $errMsg = 'Do not set field to be primary key when adding fields. ' .
                          'Instead, use the changePrimaryKey method';
                throw new \Exception($errMsg);
            }
            elseif ($field->isKey())
            {
                if ($keysString !== "")
                {
                    $keysString .= ", ";
                }
                
                if ($field->isUnique())
                {
                    $keysString .= "UNIQUE ";
                }
                
                $keysString .= "KEY (`" . $fieldName . "`) ";
            }
        }
        
        $fieldsString = implode(", ", $fieldStrings);
        
        $fieldsString .= $keysString;
        
        $query = 
            "ALTER TABLE " . 
            "`" . $this->m_name . "` " . 
            "ADD " .
            "(" . $fieldsString . ") ";
        
        $result = $this->m_mysqliConn->query($query);
        
        if ($result !== TRUE)
        {
            throw new \Exception('Error creating table with query: ' . $query);
        }
    }
public function addFields(array $fields)
    {
        foreach ($fields as $field)
        {
            $name = $field->getName();
            $addFields[$name] = $field; # we key by name to prevent duplicates!
        }
        
        $keysString = "";
        $fieldStrings = array();
        
        foreach ($addFields as $fieldName => $field)
        {
            $fieldStrings[] = $field->getFieldString();
                
            /* @var $field DatabaseField */
            if ($field->isPrimaryKey())
            {
                $errMsg = 'Do not set field to be primary key when adding fields. ' .
                          'Instead, use the changePrimaryKey method';
                throw new \Exception($errMsg);
            }
            elseif ($field->isKey())
            {
                if ($keysString !== "")
                {
                    $keysString .= ", ";
                }
                
                if ($field->isUnique())
                {
                    $keysString .= "UNIQUE ";
                }
                
                $keysString .= "KEY (`" . $fieldName . "`) ";
            }
        }
        
        $fieldsString = implode(", ", $fieldStrings);
        
        $fieldsString .= $keysString;
        
        $query = 
            "ALTER TABLE " . 
            "`" . $this->m_name . "` " . 
            "ADD " .
            "(" . $fieldsString . ") ";
        
        $result = $this->m_mysqliConn->query($query);
        
        if ($result !== TRUE)
        {
            throw new \Exception('Error creating table with query: ' . $query);
        }
    }
public function addFields ( array $ fields ) { foreach ( $ fields as $ field ) { $ name = $ field -> getName ( ) ; $ addFields [ $ name ] = $ field ; # we key by name to prevent duplicates! } $ keysString = "" ; $ fieldStrings = array ( ) ; foreach ( $ addFields as $ fieldName => $ field ) { $ fieldStrings [ ] = $ field -> getFieldString ( ) ; /* @var $field DatabaseField */ if ( $ field -> isPrimaryKey ( ) ) { $ errMsg = 'Do not set field to be primary key when adding fields. ' . 'Instead, use the changePrimaryKey method' ; throw new \ Exception ( $ errMsg ) ; } elseif ( $ field -> isKey ( ) ) { if ( $ keysString !== "" ) { $ keysString .= ", " ; } if ( $ field -> isUnique ( ) ) { $ keysString .= "UNIQUE " ; } $ keysString .= "KEY (`" . $ fieldName . "`) " ; } } $ fieldsString = implode ( ", " , $ fieldStrings ) ; $ fieldsString .= $ keysString ; $ query = "ALTER TABLE " . "`" . $ this -> m_name . "` " . "ADD " . "(" . $ fieldsString . ") " ; $ result = $ this -> m_mysqliConn -> query ( $ query ) ; if ( $ result !== TRUE ) { throw new \ Exception ( 'Error creating table with query: ' . $ query ) ; } }
Adds the specified fields to this table.
@param array $fields - an array of DatabaseField objects
Adds the specified fields to this table .