Re: add a column to a table via PHP
| From: | Sean Finkel | Date: | Tue, 13 Mar 2001 13:56:16 +0000 |
| Subject: | Re: add a column to a table via PHP | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-7422@lists.php.net to get a copy of this message | ||
Wouldn't you also need the datatype of the new column (ie. Varchar)? :-)
----------------------------------------------------------------------------
---------------------
Sean Finkel - alarion@planetunreal.com
|H|eretik - Pain in the ass for Clan |H|avoc
http://www.webdrenalin.com/ubbcgi/
Webmaster - Rabid Wolf .:: Food For Your Brain ::.
http://www.rabid-wolf.com
Lead Programmer - Data Admin and Data Lib
http://dadmin.sourceforge.net
----------------------------------------------------------------------------
---------------------
----- Original Message -----
From: "ME" <qwerty.com@web3.intercession.net>
To: <php-db@lists.php.net>
Sent: Tuesday, March 13, 2001 7:36 PM
Subject: RE: [PHP-DB] add a column to a table via PHP
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.
--
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