ich suche eine recht schnelle und simple Methode um Einträge in MySQL nur dann hinzuzufügen, wenn sie bereits nicht existieren (nach einer ID identifizierbar), sonst wird der Eintrag aktuallisiert.
Natürlich könnte ich das mit PHP ganz einfach über 3 Befehle lösen ... aber bei mehreren hunderten Einträgen wäre das nicht gerade aus schnell.
Das ist eig. ein Cronjob von mir der alle 5 Minuten aufgerufen wird und Einträge überprüft ob diese immer noch identisch sind oder ob halt neue dazu gekommen sind. Deswegen sollte es auch recht schnell funktioniert
Ich finde es jetzt sehr peinlich meinerseits
Ich bin schon so oft auf diesen Link gestoßen, doch irgend wie habe ich das "ON DUPLICATE KEY UPDATE" jedes mal überlesen oder nicht wahr genommen
Danke, funktioniert jetzt alles so wie es sollte. Ich hoffe die Geschwindingkeit ist auch ausreichend (habe es noch nicht ganz getestet)
Ich habe eine Tabelle mit den Spalten id, name, type und id hat einen Primary Key und Autoincrese (oder so).
Jetzt möchte ich etwas in die Tabelle eintragen aber nur, wenn der "name" bereits nicht existiert und wenn er es doch tut dann soll "type" aktuallisiert werden.
Dann erstellt er bei mir einen neuen Eintrag ... was ich nicht möchte.
Brauchst du das in einem Query? Oder gehts auch in 2?
Du müsstest der Spalte Name eben einen UNIQUE Key geben.
Oder per:
Code:
IF EXISTS(SELECT type WHERE name=Value(name) FROM tabelle )
then
UPDATE tabelle
SET type = Value(type)
WHERE name=Value(Name)
ELSE
INSERT INTO tabelle (id, name, type)
VALUES (id, name, type);
Hmm, ich finde jetzt nicht den Fehler. Woran könnte es liegen?
Code:
mysql> IF EXISTS(SELECT `type` WHERE `wort`= Value(`wort`) FROM `words`)
THEN
UPDATE `words`
SET `type` = Value(`type`), `update` = Value(`update`)
WHERE `wort`= Value(`wort`)
ELSE
INSERT INTO `words` (`wort`, `type`, `update`)
VALUES ('ich', 'Pronomen', '1418036206');
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF EXISTS(SELECT `type` WHERE `wort`= Value(`wort`) FROM `words`)
THEN
UPDAT' at line 1
Joa das dachte ich am Anfang auch aber anscheinend ist es nicht der Fehler :/
Code:
mysql> IF EXISTS(SELECT `type` FROM `words` WHERE `wort`= Value(`wort`))
THEN
UPDATE `words`
SET `type` = Value(`type`), `update` = Value(`update`)
WHERE `wort`= Value(`wort`)
ELSE
INSERT INTO `words` (`wort`, `type`, `update`)
VALUES ('ich', 'Pronomen', '1418036206');
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF EXISTS(SELECT `type` FROM `words` WHERE `wort`= Value(`wort`))
THEN
UPDA' at line 1
PHP / MYSQL Insert REAGIERT NICHT 05/05/2014 - Web Development - 9 Replies Hallo leute,
wollte mittels eines PHP-Scripts Daten in meine Tabelle einfügen.
Es kommt auch keine Fehlermeldung wenn ich bsp. OR DIE ("Fail"); hinzufüge, allerdings
werden die Einträge einfach nicht in die Tabelle übertragen.
Erkennt ihr einen Fehler?
<html>
<head>
<title> Test </title>
MySQL INSERT INTO trägt nicht alle Daten aus Formular ein 08/26/2012 - Web Development - 14 Replies Hallo, ich wollte mir eine kleine Regi basteln.
Dabei stoße ich auf das Problem, dass Username sowie Password eingetragen werden aber die E-Mail nicht. Hier einmal der komplette Code sowie DB:
Das Formular:
<link rel="stylesheet" type="text/css" href="../style.css" />
<h3>Registrierung</h3>
<form action="index.php?page=reg" method="post" id="regist">
<table width="400" border="0" align="center">
<tr>
Mysql 5.5 fehler Account existiert bereits 06/07/2012 - Metin2 Private Server - 6 Replies Hallo
Ich habe seit dem ich Mysql 5.5 benutze den fehler beim hen! cms Account existiert bereits bei jede anmeldung aber account tabelle ist leer bei mysql 5.0 geht alles
[Release] MySQL Insert system 07/18/2010 - CO2 PServer Guides & Releases - 18 Replies Ello!
First of all, this is NOT sourcedependent, which means you can use this on any source without modifying the code.
This is an replacement for all of you who still uses normal MySQL queries. Use this code to clean up, make it easier and more orginazed.
Here's how it looks:
Example: (Original (LOTF for example))
[HELP]C# MySQL Command insert if not exsist? 09/04/2009 - CO2 Private Server - 8 Replies MySqlCommand Command = new MySqlCommand("INSERT INTO accounts(AccountID,LogonType) VALUES ('" + fillBox.Text + "','3')", Connection);
Now, I want it to check if the value of fillBox.Text doesn't excist before making the account, so It wont create the same account. I tried making it in a try, that didn't help, it just make several accounts with the same name.
~Bas