Hi all
i have table with index on three column to avoid some duplicate cases
now i want to insert data to in and ignore insert if record with index already exist

may any one can help me ?!

Comments

alter table customers add unique index(user, email, address);

Dear manish
i did indexing
my table already has index
know how to ingore this index in inserting in duplicate cases

where the wild roses grow ?

index is set but you must set unique index. that;s why i give you a simple solution which alter table and set unique index.

i did,
it prevent from inserting duplicated row, but i show error in each event, i want to solve that without error happening,

i mean each time script faced with duplicate row it prevent from inserting and continue application flow

where the wild roses grow ?

This will only work if you are using mysql:

<?php
db_query
(
 
'INSERT INTO {some_table} ' .
 
'(col1, col2) ' .
 
'VALUES (:val1, :val2) ' .
 
'ON DUPLICATE KEY UPDATE col1 = :val1 ',
  array
  (
   
':val1' => 'some_value',
   
':val2' => 'some_other_value',
  )
);
?>

Note that col1, or a combination of col1 and col2, must be the primary key for {some_table}.

Jaypan
Our newest Drupal site: PacificAikido.com (Drupal showcase)

thats nice,

is it way to implement this with some thing like

<?php
  db_insert
('some_table')->addExpression(' ON DUPLICATE key Update  ');
?>

?!

where the wild roses grow ?

You can implement it exactly as I showed above.

Jaypan
Our newest Drupal site: PacificAikido.com (Drupal showcase)

nice tip Jaypan thanks

where the wild roses grow ?