On 21-May-2004 Andre wrote:
> 
> Hello...
> Someone now or have script's about   insert, change and remove fields
> like Enum in one table.
> Thanks .
> 

For sets (Emum should be similar) :

function getsetvalues($tbl, $fld) {
    global $dbconn;

    $search=array('set(', ')', "'");

    $qry="SHOW COLUMNS FROM $tbl LIKE '$fld'";
    $r = $dbconn->Execute($qry);
    if ($row = $r->FetchRow()) {
        if (! empty($row['Default']))
            $cv['__Default__'] = stripslashes($row['Default']);
        $s=str_replace($search, '', stripslashes($row['Type']));
        $l=explode(',', $s);
        foreach($l as $v) 
            $cv[$v] = 1;
    }
    return($cv);
}

// add to set:
    $cv[$new] = 1;
    $dflt = $cv['__Default__']; unset($cv['__Default__']);
    $s = implode("','", array_keys($cv));
    $qry = "ALTER TABLE $tbl CHANGE COLUMN 
          $fld $fld SET('$s') NOT NULL DEFAULT '$dflt'";

// I'm sure you can figure out the rest

Regards,
-- 
Don Read                                     [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to 
   steal the neighbor's newspaper, that's the time to do it.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to