Обсуждение: replace??

Поиск
Список
Период
Сортировка

replace??

От
bboett@erm1.u-strasbg.fr (Bruno Boettcher)
Дата:
hello,

i have the following problem:
i have in php an array structure with user-prefs that have to be stored
onto DB....

actually i look up if the corresponding entry exists (comparing
user-name and field-name) if yes i update, if no i insert....

this isn't very appealing, but i couldn't find another way yet to make
this shorter...

would be nice if something like the following existed:

replace settings set auser='toto',field='lang',data='fr' where
auser='toto' and field='lang';

update settings set auser='toto',field='lang',data='fr' where
auser='toto' and field='lang' REPLACE;

or even better:

replace settings keys(auser,field) set auser='toto',field='lang',data='fr';


-- 
ciao bboett
==============================================================
bboett@earthling.net
http://inforezo.u-strasbg.fr/~bboett http://erm1.u-strasbg.fr/~bboett
===============================================================
the total amount of intelligence on earth is constant.
human population is growing....


Re: replace??

От
"Brett W. McCoy"
Дата:
On Tue, 19 Dec 2000, Bruno Boettcher wrote:

> actually i look up if the corresponding entry exists (comparing
> user-name and field-name) if yes i update, if no i insert....
>
> this isn't very appealing, but i couldn't find another way yet to make
> this shorter...
>
> would be nice if something like the following existed:
>
> replace settings set auser='toto',field='lang',data='fr' where
> auser='toto' and field='lang';
>
> update settings set auser='toto',field='lang',data='fr' where
> auser='toto' and field='lang' REPLACE;

What is the difference between replacing data and updating data in this
sense?

What you might want to do with your array (which in PHP can also function
as a hash, with string indices) is create a wrapper class that kind of
emulates a hash tied to the DB like one might do in Perl, so that whenever
you 'store' a value in the array (via a method), it will automagically
update or insert into the underlying database.  PHP doesn't do ties
explicitly, but you can emulate this behaviour with a PHP class.

-- Brett                                    http://www.chapelperilous.net/~bmccoy/
---------------------------------------------------------------------------
The price of greatness is responsibility.