• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 489
  • Last Modified:

INSERT IGNORE SQL STATEMENT mysql php

When using a statement like INSERT IGNORE INTO table VALUES ('1','2','3') in php

How can I determine if the record was inserted or ignored?

for instance when I want to know if a sql statement executed correctly I would use something like

if ($sql) {
echo "ok";
} else {
echo "Not ok";
}

but since the sql statement executes correctly whether it is skipped or ignored how can I differentiate the two?

0
cbielich
Asked:
cbielich
2 Solutions
 
nkraynevCommented:
you can use mysql_affected_rows() function. It would return >0 if any records inserted

PS btw, you can change rows if they ignored:
insert ignore into ..... ON DUPLICATE KEY UPDATE name="value",name2="value2"...
0
 
Ray PaseurCommented:
See the man page here:
http://us.php.net/manual/en/function.mysql-affected-rows.php

Note what happens if the count is zero, one or more, or (drum roll) negative one!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now