RE: [PHP-DB] ALTER TABLE - code not working.

From: Date: Thu, 29 Mar 2001 14:32:23 +0000
Subject: RE: [PHP-DB] ALTER TABLE - code not working.
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-7978@lists.php.net to get a copy of this message
While I appreciate your comments about metabase I simply don't have time to start the project again, it has taken a long time to get this far. Perhaps I'll look at metabase for future developments. In the meantime, anyone seeing this message for the first time, I'm still struggling with my code below: Martin. -----Original Message----- From: Manuel Lemos [mailto:mlemos@acm.org] Sent: 29 March 2001 14:05 To: php-db@lists.php.net; Martin E. Koss Subject: Re: [PHP-DB] ALTER TABLE - code not working. 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","myusername","mypassword"); 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. YES! You assume right. Martin. 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: php-db-unsubscribe@lists.php.net For additional commands, e-mail: php-db-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.db (#7978) next »