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

2001-03-13 Thread Martin E. Koss

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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




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

2001-03-13 Thread ME

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:[EMAIL PROTECTED]]
Sent: Tuesday, March 13, 2001 12:22 PM
To: [EMAIL PROTECTED]
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




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

2001-03-13 Thread Martin E. Koss

Thanks,
Not being as lazy as I thought, I had coded this shortly after sending the
e-mail.
I was been really lazy as it only took a few moments thought and typing!!!

Mr. Lazy!

Thanks again.

Martin

-Original Message-
From: ME [mailto:[EMAIL PROTECTED]]
Sent: 13 March 2001 19:37
To: [EMAIL PROTECTED]
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:[EMAIL PROTECTED]]
Sent: Tuesday, March 13, 2001 12:22 PM
To: [EMAIL PROTECTED]
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
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]




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

2001-03-13 Thread ME

Yes, you're quite right.  Mea culpa...

-Original Message-
From: Sean Finkel [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 13, 2001 7:56 AM
To: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] add a column to a table via PHP


Wouldn't you also need the datatype of the new column (ie. Varchar)? :-)


-
Sean Finkel - [EMAIL PROTECTED]
|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" [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
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:[EMAIL PROTECTED]]
Sent: Tuesday, March 13, 2001 12:22 PM
To: [EMAIL PROTECTED]
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
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]


-- 
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]