11. juli 2001 - 22:08Der er
6 kommentarer og 1 løsning
REPLACE
Hvordan er syntaxen til cmd\'em REPLACE... jeg kan ikke finde det der ligner dokumentation på den og mit script virker ikke helt efter hensigten når jeg bruger kommandoen!
REPLACE works exactly like INSERT, except that if an old record in the table has the same value as a new record on a unique index, the old record is deleted before the new record is inserted. See section 7.21 INSERT Syntax.
In other words, you can\'t access the values of the old row from a REPLACE statement. In some old MySQL version it looked like you could do this, but that was a bug that has been corrected.
When one uses a REPLACE command, mysql_affected_rows() will return 2 if the new row replaced and old row. This is because in this case one row was inserted and then the duplicate was deleted.
The above makes it easy to check if REPLACE added or replaced a row.
REPLACE works exactly like INSERT, except that if an old record in the table has the same value as a new record on a unique index, the old record is deleted before the new record is inserted.
Dvs. du behøver ikke bruge update, hvis der allerede er en tupel med pågældende id.
Ok, mit problem er så at jeg en række med id# 1. Denne laver jeg nu en replace på..... men enten skriver den ikke, eller også opretter den en ny række. Hvad er det liige der går galt?
det er mere jeg har haft spurgt folk ang. specificeringen af id\'et, og alle svarer forskelligt....
mysql_query(\"REPLACE INTO TWDrettesys (\".$fields.\") VALUES (\".$values.\")\");
CREATE TABLE TWDrettesys ( id smallint(5) unsigned NOT NULL auto_increment, mynavnirl text NOT NULL, myalder smallint(3) unsigned DEFAULT \'0\' NOT NULL, mymail tinytext NOT NULL, myicq int(10) unsigned DEFAULT \'0\' NOT NULL, myforbindelse text NOT NULL, myfavoritvaaben text NOT NULL, mycomputer text NOT NULL, myrang tinytext NOT NULL, mykommentar text NOT NULL, PRIMARY KEY (id) );
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.