You are here: Re: Database abstraction layers « PHP Programming Language « IT news, forums, messages
Re: Database abstraction layers

Posted by NC on 11/19/31 11:47

Colin McKinnon wrote:
>
> There's lots of DB abstraction layers out there, but a quick look around
> them hasn't turned up anything which seems to met my requirements.

Which probably means that you shouldn't even attempt to solve your
problem with an abstraction layer; easier solutions might be
available...

> I want some code where I present an array of data, and the corresponding
> primary key and let the code work out whether to INSERT or UPDATE it

You don't need PHP code for that; this can be handled on the database
level:

INSERT INTO the_table
SET field1=value1, field2=value2, field3=value3, ...
ON DUPLICATE KEY UPDATE field1=value1, field2=value2, field3=value3,
....

This syntax is available since MySQL 4.1.0.

You could also use a REPLACE query, but keep in mind that it works by
deleting the old record and inserting a new one, so if there are fields
that exist in the table, but not in the query, they will be lost.

Cheers,
NC

 

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

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