Alternative for ON DUPLICATE KEY UPDATE
Moderator: General Moderators
Alternative for ON DUPLICATE KEY UPDATE
Im creating a list of SQL Statments in PHP.
I need to have an INSERT statement that'll skip if theres a duplicate key.
ON DUPLICATE KEY UPDATE is only available from MySQL 4.1.0
Any workaround for prev versions ? (MySQL solution not PHP)
Thanks
I need to have an INSERT statement that'll skip if theres a duplicate key.
ON DUPLICATE KEY UPDATE is only available from MySQL 4.1.0
Any workaround for prev versions ? (MySQL solution not PHP)
Thanks
god i couldn't even imagine attempting that
that could either be very fun to learn or a good way for me to get bald really quick..
only thing i know to do is a mix between what feyd and tim said.. except i'd do what you aren't wanting to do and that is use php..
imo, it would just be a lot easier... all ur gonna be doing anyways is one query statement anyways
yeah, i understand that if you have a lot of sql statements it's gonna get long.. but imo it's either that or tell ur web host to update to a newer version and be done with it heh.. otherwise, tell them that ur gonna leave and move to phpwebhosting.com 
only thing i know to do is a mix between what feyd and tim said.. except i'd do what you aren't wanting to do and that is use php..
imo, it would just be a lot easier... all ur gonna be doing anyways is one query statement anyways
Code: Select all
$sql = mysql_query("select * from fu where bar = 'fubar'");
$num=mysql_num_rows($sql);
if($num > 0)
{
echo 'entry already exists';
exit;
}
//update tableWell I have a script that creates a sql file with a lot of INSERT statements.
Its this SQL file that I've to give to my client and not a PHP one.
Hes just going to import that file into his db.
Thats why Im looking for pure SQL methods.
Thought of using an IF statement but thats not working either - though its supported since 3.23 - viewtopic.php?t=31880
Its this SQL file that I've to give to my client and not a PHP one.
Hes just going to import that file into his db.
Thats why Im looking for pure SQL methods.
Thought of using an IF statement but thats not working either - though its supported since 3.23 - viewtopic.php?t=31880