Hello,

"Martin E. Koss" wrote:
> 
> I have been trying to get a new column added to a table (vips) via a PHP
> script, but having exhausted all the things I can find, I'm still
> struggling. I've referred t TFM for all those who just can't wait to tell me
> to do so, and believe my SQL statement is correct:
> 
> $NewCol = $Prod_Code;
> $defaultvalue = "0.00";
> // make usual connection
> $conID = mysql_pconnect ("localhost","admin","mek1233");
> mysql_select_db("FocusDynamics", $conID);
> // set the query
> $AddColQuery = "ALTER TABLE vips ADD COLUMN $NewCol";
> $result = mysql_query ($AddColQuery,$conID);
> // now set the default value for all rows in vips table
> $SetDefault = "UPDATE TABLE vips SET $NewCol=$defaultvalue";
> $result = mysql_query ($SetDefault,$conID);
> 
> It is NOT adding the column, and obviously not setting the default.

I presume that the $Prod_Code is just the name of the field. You also
need to declare the type of the field. BTW, if you declare the default
value too in the ALTER TABLE statement the existing rows will be filled
with that value in that column.

You may want to look at Metabase which is a PHP database abstraction
package that is able to install and maintain database schema giving just
a schema description file defined in a specific XML format. Metabase is
able to parse the schema definitions and install any tables, fields,
indexes and sequences described in the schema definition.

When you want to change anything in your schema (adding, removing,
altering tables, fields, indexes and sequences) Metabase manager will
figure the changes you made in the schema definition and apply them to
the installed database without disturbing any data already inserted
after the first time the schema was installed or it was changed for the
last time. No sweat, no risk mistake. Look at Metabase here:

http://phpclasses.UpperDesign.com/browse.html/package/20

Manuel Lemos

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to