Re: How to insert, change and remove fields like Enum

From: Date: Sun, 23 May 2004 22:59:53 +0000
Subject: Re: How to insert, change and remove fields like Enum
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-186811@lists.php.net to get a copy of this message
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 dread@ispwest.net -- 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.

« previous php.general (#186811) next »