RE: [PHP-DB] add a column to a table via PHP

From: Date: Tue, 13 Mar 2001 19:36:37 +0000
Subject: RE: [PHP-DB] add a column to a table via PHP
Groups: php.db 
Request: Send a blank email to php-db+get-7418@lists.php.net to get a copy of this message
The following assumes you've already selected the database and that $column contains the name of the new column and $defaultvalue is the value to be set. $query = "ALTER TABLE Prices ADD $column DEFAULT \"$defaultvalue\""; mysql_query($query) or die("Can't add column to Prices"); $query = "UPDATE TABLE Prices SET $column=$defaultvalue"; mysql_query($query) or die("Can't update table Prices"); And, yes, you are a bit lazy...<GRIN> This is in the manual. -----Original Message----- From: Martin E. Koss [mailto:mek@mek.co.uk] Sent: Tuesday, March 13, 2001 12:22 PM To: php-db@lists.php.net Subject: [PHP-DB] add a column to a table via PHP Hi, I'm probably being a bit lazy asking what I should be able to figure out, but here goes anyway: What I want to do, in response to certain other actions having taken place, is add a column to a mySQL database (FocusShop) table (Prices) and set the default value of that column and update all existing rows in that table to the same value for that new column. Has anyone got the correct way to do this? Thanks, Martin.

« previous php.db (#7418) next »