You are here: Re: [PHP] Re: Inserting NULL Integer Values « PHP « IT news, forums, messages
Re: [PHP] Re: Inserting NULL Integer Values

Posted by "Shaun" on 10/18/05 22:15

Hi all,

Thanks for your replies, rather than check each vaule by name I am trying to
produce a more dynamic solution:

foreach ($_POST as $key => $value) {
if ($value == '') {
$_POST[$key] == 'NULL';
}
}

I was expecting $_POST[$key] to be the same as $key, however this isnt the
case:

$key = city
$_POST[$key] = London
$value = London

Any ideas?

""Richard Lynch"" <ceo@l-i-e.com> wrote in message
news:6246.67.108.68.36.1129661387.squirrel@www.l-i-e.com...
> On Tue, October 18, 2005 12:42 pm, tg-php@gryffyndevelopment.com wrote:
>> That should work. You can set it so you can't have NULL, but dont
>> know of anything that tells the database not to accept '' as a value
>
> Any database, other than MySQL, is *NOT* going to accept '' as an
> integer value.
>
> Because '' is not an integer by any stretch of the imagination.
>
> If you don't care about ever porting your application to something
> other than MySQL, then you can IGNORE the advice to not use '' on
> integers.
>
> If there's ANY possibility that some day somebody might maybe wanna
> use a different database with your application, then don't confuse
> strings with integers.
>
> Actually, it might be better for your own
> education/sanity/comprehension/documentation/code to not confuse
> strings and integers with '' around integers in the SQL, but if
> everything ELSE is good in your code, and it's "always going to be
> MySQL" then it's fine.
>
> Note that:
>
> $value2 = 'NULL'; //PHP $value2 is a string
>
> $query = "insert into (integer_field) values ($value2)";
> //PHP $query is a string, but...
>
> The place-holder in $value2 will be just: NULL
>
> No quotes.
>
> No apostrophes.
>
> Not a string.
>
> NULL
>
> SQL NULL value representing "no value"
>
> --
> Like Music?
> http://l-i-e.com/artists.htm

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация