Example #1
0
 /**
  * Alter table
  *
  * @param string $table
  * @param string $fieldName
  * @param string $type
  * @param int $length
  * @param int $decimalLength
  * @param bool $unsigned
  * @param string $comment
  */
 public function alterTableAdd($table, $fieldName, $type, $length, $decimalLength, $unsigned, $comment = "")
 {
     $query = "ALTER TABLE " . $this->db->quote($table) . " ADD " . $this->db->quote($fieldName) . " ";
     $query .= $type . " ";
     if (is_int($length)) {
         if (is_int($decimalLength)) {
             $query .= "({$length}, {$decimalLength})";
         } else {
             $query .= "({$length})";
         }
     }
     if ($unsigned && preg_match("~int\$|^double|^real|^float|^decimal|^serial~", $type)) {
         $query .= " UNSIGNED ";
     }
     $query .= " NULL ";
     if ($comment) {
         $query .= " COMMENT " . $this->db->toDb((string) $comment);
     }
     $this->db->query($query);
 }