RE: [PHP] Global Changes With Loop To Allow Nulls In A Table...
| From: | Boyd, Todd M. | Date: | Tue, 27 Jan 2009 17:58:01 +0000 |
| Subject: | RE: [PHP] Global Changes With Loop To Allow Nulls In A Table... | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-287224@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Andrew Ballard [mailto:aballard@gmail.com]
> Sent: Tuesday, January 27, 2009 11:39 AM
> To: revDAVE
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] Global Changes With Loop To Allow Nulls In A
> Table...
>
> On Tue, Jan 27, 2009 at 11:53 AM, revDAVE <Cool@hosting4days.com>
> wrote:
> > Hi Folks,
> >
> > Newbie question....
> >
> > I have a mysql table with 100 fields, currently all do not allow
> nulls.
> > Rather than hand typing in phpMyAdmin, I would like a way to loop
> through
> > all fields and update them to allow nulls....
> >
> > My Beginning attempt needs help...
> >
> >
> > $i = 1;
> > while ($i <= 100):
> >
> > // how do I word this to just change whatever field we are on to
> allow
> > nulls?
> >
> > $sql = 'ALTER TABLE
mytable ?*update*?
> '.$???WhatEverField??[$i].'
> > ?ALLOWNULL?;';
> >
> > //mysql_query($sql);
> >
> > $result = mysql_query($sql) or die("<br /><br /> Could not renumber
> dB $sql
> > <br /><br />" . mysql_error());
> >
> >
> > $i++;
> > endwhile;
>
>
> The other responses should get you started if this is something you
> really want to do. However, I'll play devil's advocate here and just
> raise the question why you would want to make this change in the first
> place. I'm not quite as anti-NULL as a lot of arguments I've read
> against them, but I tend to agree that the number of columns that
> accept NULL values should be kept as small as possible. Even if you
> decide that you need to allow NULL values in some cases, IMHO I
> wouldn't write a script that ran through my entire database and opened
> every column in every table to accept.
I just thought I'd throw this out there...
A lot of people who post questions on this list are programming their algorithms and structuring
their applications in a certain way because that's what the client wants, or that's what
their boss told them to do. Yes, accepting NULL values in a database is frowned upon (unless the
table is a transaction table)... but I doubt his boss or his client cares in the least.
My 2 cents. ;)
// Todd